> I wrote a small micro-benchmark utility[1] to test various time syscalls and > the results were a bit surprising to me. The results were from a UP machine > and I believe that the difference between gettimeofday(2) and > clock_gettime(CLOCK_REALTIME_FAST) would've been bigger on an SMP system and > performance would've degraded further with each additional core. > > clock_gettime(CLOCK_REALTIME_FAST) is likely the ideal function for most > authors (CLOCK_REALTIME_FAST is supposed to be precise to +/- 10ms of > CLOCK_REALTIME's value[2]). In fact, I'd assume that CLOCK_REALTIME_FAST is > just as accurate as Linux's gettimeofday(2) (a statement I can't back up, > but believe is likely to be correct) and therefore there isn't much harm (if > any) in seeing clock_gettime(2) + CLOCK_REALTIME_FAST receive more > widespread use vs. gettimeofday(2). FYI. -sc > > PS Is there a reason that time(3) can't be implemented in terms of > clock_gettime(CLOCK_SECOND)? 10ms seems precise enough compared to time_t's > whole second resolution. > > % ./bench_time 9079882 | sort -rnk1 > Timing micro-benchmark. 9079882 syscall iterations. > Avg. us/call Elapsed Name > 9.322484 84.647053 gettimeofday(2) > 8.955324 81.313291 time(3) > 8.648315 78.525684 clock_gettime(2/CLOCK_REALTIME) > 8.598495 78.073325 clock_gettime(2/CLOCK_MONOTONIC) > 0.674194 6.121600 clock_gettime(2/CLOCK_PROF) > 0.648083 5.884515 clock_gettime(2/CLOCK_VIRTUAL) > 0.330556 3.001412 clock_gettime(2/CLOCK_REALTIME_FAST) > 0.306514 2.783111 clock_gettime(2/CLOCK_SECOND) > 0.262788 2.386085 clock_gettime(2/CLOCK_MONOTONIC_FAST) > Last value from gettimeofday(2): 1212380080.620649 > Last value from time(3): 1212380161 > Last value from clock_gettime(2/CLOCK_VIRTUAL): 2.296430000 > Last value from clock_gettime(2/CLOCK_SECOND): 1212380338.000000000 > Last value from clock_gettime(2/CLOCK_REALTIME_FAST): 1212380243.461081040 > Last value from clock_gettime(2/CLOCK_REALTIME): 1212380240.459788612 > Last value from clock_gettime(2/CLOCK_PROF): 185.560343000 > Last value from clock_gettime(2/CLOCK_MONOTONIC_FAST): 5747219.271879584 > Last value from clock_gettime(2/CLOCK_MONOTONIC): 5747216.886509281
rozetta~/devel/c%>sysctl hw.model hw.model: Intel(R) Xeon(R) CPU E5345 @ 2.33GHz rozetta~/devel/c%>./bench_time 9079882 | sort -rnk1 Timing micro-benchmark. 9079882 syscall iterations. Avg. us/call Elapsed Name 1.405469 12.761494 clock_gettime(2/CLOCK_REALTIME) 1.313101 11.922799 time(3) 1.305518 11.853953 clock_gettime(2/CLOCK_MONOTONIC) 1.303947 11.839681 gettimeofday(2) 0.442908 4.021557 clock_gettime(2/CLOCK_PROF) 0.436484 3.963223 clock_gettime(2/CLOCK_VIRTUAL) 0.217718 1.976851 clock_gettime(2/CLOCK_MONOTONIC_FAST) 0.215264 1.954571 clock_gettime(2/CLOCK_REALTIME_FAST) 0.211779 1.922932 clock_gettime(2/CLOCK_SECOND) Value from time(3): 1212391638 Last value from gettimeofday(2): 1212391626.146308 Last value from clock_gettime(2/CLOCK_VIRTUAL): 4.179847000 Last value from clock_gettime(2/CLOCK_SECOND): 1212391676.000000000 Last value from clock_gettime(2/CLOCK_REALTIME_FAST): 1212391652.785214038 Last value from clock_gettime(2/CLOCK_REALTIME): 1212391650.830730996 Last value from clock_gettime(2/CLOCK_PROF): 60.276182000 Last value from clock_gettime(2/CLOCK_MONOTONIC_FAST): 1190915.000747909 Last value from clock_gettime(2/CLOCK_MONOTONIC): 1190913.024357334 gettimeofday is 6 times slower on this system, 28 times slower on your system. -- regards Claus When lenity and cruelty play for a kingdom, the gentlest gamester is the soonest winner. Shakespeare _______________________________________________ freebsd-performance@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-performance To unsubscribe, send any mail to "[EMAIL PROTECTED]"