summary refs log tree commit diff
diff options
context:
space:
mode:
authorQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-04-05 15:52:18 -0400
committerQuentin Carbonneaux <quentin.carbonneaux@yale.edu>2015-09-15 23:01:26 -0400
commit209a80bb669ae1c8d25a195b4d22cc1a1cfa1ddf (patch)
treebc902c0e772f130ef1b24c270d02d01eb036752b
parentff14ce3197e420a00e56be7afef70db6a283ace6 (diff)
downloadroux-209a80bb669ae1c8d25a195b4d22cc1a1cfa1ddf.tar.gz
run multiple rounds for stable timing
-rw-r--r--tmain.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/tmain.c b/tmain.c
index 0031fc2..79e1c24 100644
--- a/tmain.c
+++ b/tmain.c
@@ -1,16 +1,23 @@
 #include <stdio.h>
 #include <time.h>
 
+enum { NRounds = 150 };
+
 extern long f(void);
 
 int main()
 {
-	clock_t t0;
-	long l;
+	clock_t t0, tmin;
+	long i, l;
 
-	t0 = clock();
-	l = f();
-	t0 = clock() - t0;
+	tmin = 10 * CLOCKS_PER_SEC;
+	for (i=0; i<NRounds; i++) {
+		t0 = clock();
+		l = f();
+		t0 = clock() - t0;
+		if (t0 < tmin)
+			tmin = t0;
+	}
 	printf("f() = %ld\n", l);
 	printf("  %.4f secs\n", (double)t0/CLOCKS_PER_SEC);
 	return 0;