Log in

No account? Create an account

How fast is your clock?

« previous entry | next entry »
Feb. 4th, 2008 | 10:58 pm

I was looking today at the set_current_time() call in memcached looking for a bug and noticed this bit of code:

new_time = (rel_time_t) (time(0) - stats.started);

What is the issue? Time!

No two time calls cost the same.

The difference?

gettimeofday() 14.558
time() 14.664
clock_gettime() 13.958

All of these were compared in a loop. The obvious winner is clock_gettime() though it Linux specific so an ifdef is needed so that other platforms can use gettimeofday().

I suspect it can be made to be faster :)

Link | Leave a comment |

Comments {4}


(no subject)

from: kytty
date: Feb. 5th, 2008 02:23 pm (UTC)

Fun observation! :)

Reply | Thread


(no subject)

from: ratchet
date: Feb. 5th, 2008 04:21 pm (UTC)

clock_gettime is POSIX standard, not linux-specific. I've used it in Solaris and Mac OS X as well.

Reply | Thread

Brian "Krow" Aker

(no subject)

from: krow
date: Feb. 6th, 2008 02:55 am (UTC)

I know that it is POSIX, but I was under the impression that it was still not that common. I've not looked on Solaris (there is a different call I use there).

Looking around on OSX I don't see it in /usr/include and there is no man page. Got any additional information on it?

Reply | Parent | Thread

Fast clocks testing code

from: evilmonster
date: Feb. 8th, 2008 07:21 am (UTC)

I'm not sure your conclusions are correct. Try this one:


Reply | Thread