I'm working in C and I need to get current time in miliseconds. Time.h can only return time in seconds. Does anyone know which function, or library could do that?
I'm working in C and I need to get current time in miliseconds. Time.h can only return time in seconds. Does anyone know which function, or library could do that?
What OS?
time() is a generic function that is portable, but there are several different ways to get time in various systems. Also, if you want to measure "CPU time", rather than wall-clock time, have a look at:
http://www.hmug.org/man/3/clock.php
The latter is useful for benchmarking and such.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
i'm working in ubuntu. i need one program(server) to send a message containing its current time in miliseconds to another client, which should then return the message so that the server could measure the latency.
have a look at this FAQ
ssharish
The main point of that FAQ is to look into the usage if Clock function. That gives an idea of millionth second.
ssharish
clock won't work. frist value returned is 0, i sent it to the client, made client wait for 1 sec before sending it back. then i used clock function again and the new value returned was 0 again.
gettimeofday() returns a struct containing seconds and microseconds.
Though it is down to your implementation to define the resolution at which it updates the microsecond field.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
it works! Thanks!