This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Preheat CPU in benchtests


Hi, 

Benchmarks now are affected by cpu scaling when initialy run at low
frequency.

Following benchmark runs nonsensial loop first to ensure that benchmark
are measured at maximal frequency. This greatly cuts time needed to
get accurate results.

Ondra

	* benchtests/bench-skeleton.c (main): Preheat CPU.

---
 benchtests/bench-skeleton.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/benchtests/bench-skeleton.c b/benchtests/bench-skeleton.c
index 13f986d..08d7c20 100644
--- a/benchtests/bench-skeleton.c
+++ b/benchtests/bench-skeleton.c
@@ -21,6 +21,9 @@
 #include <stdio.h>
 #include <time.h>
 #include <inttypes.h>
+#include <math.h>
+
+double dontoptimize = 0.0;
 
 int
 main (int argc, char **argv)
@@ -29,6 +32,12 @@ main (int argc, char **argv)
   uint64_t total = 0, max = 0, min = 0x7fffffffffffffff;
   struct timespec start, end;
 
+  /* This loop should cause CPU switch to maximal freqency.  This makes
+     subsequent measurement more accurate.  We need side effect to avoid loop
+     being deleted by compiler.  */
+  for(k = 0; k < 1000000; k++)
+    dontoptimize += exp(k);
+
   memset (&start, 0, sizeof (start));
   memset (&end, 0, sizeof (end));
 
-- 
1.7.4.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]