From: Paul E. McKenney Date: Sat, 13 Jun 2009 23:53:05 +0000 (-0400) Subject: Fix test_looplen, use double-precition arithmetic X-Git-Tag: v0.1~146 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=85d2a666dfa980fec205a4bce7f6b53cdbed83c0;p=userspace-rcu.git Fix test_looplen, use double-precition arithmetic Here you go!!! [root@perfsqh userspace-rcu]# ./test_looplen CALIBRATION : 0 cycles per loop Hmmm... Probably not what you had in mind. Breaking out the floating-point arithmetic: [root@perfsqh userspace-rcu]# ./test_looplen CALIBRATION : 0.386172 cycles per loop time_tot = 4049312, LOOPS = 1048576, TESTS = 10 More helpful? ;-) Thanx, Paul Signed-off-by: Paul E. McKenney Signed-off-by: Mathieu Desnoyers --- diff --git a/test_looplen.c b/test_looplen.c index 86d0386..e07409a 100644 --- a/test_looplen.c +++ b/test_looplen.c @@ -71,6 +71,7 @@ int main(int argc, char **argv) unsigned long i; cycles_t time1, time2; cycles_t time_tot = 0; + double cpl; for (i = 0; i < TESTS; i++) { time1 = get_cycles(); @@ -78,10 +79,11 @@ int main(int argc, char **argv) time2 = get_cycles(); time_tot += time2 - time1; } - time_tot /= TESTS; - time_tot /= LOOPS; + cpl = ((double)time_tot) / (double)TESTS / (double)LOOPS; - printf("CALIBRATION : %llu cycles per loop\n", time_tot); + printf("CALIBRATION : %g cycles per loop\n", cpl); + printf("time_tot = %llu, LOOPS = %d, TESTS = %d\n", + time_tot, LOOPS, TESTS); return 0; }