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?
Printable View
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
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.
it works! Thanks!