diff options
author | Ondrej Bilka <neleai@seznam.cz> | 2013-05-08 08:21:05 +0200 |
---|---|---|
committer | Ondrej Bilka <neleai@seznam.cz> | 2013-05-08 08:25:08 +0200 |
commit | bb7cf681e90d5aa2d867aeff4948ac605447de7d (patch) | |
tree | ac1b16c1eb024734fdddebee2bb051d7b2c8389b /benchtests | |
parent | ba8539473296645ef5e710e506534682f9eb5572 (diff) | |
download | glibc-bb7cf681e90d5aa2d867aeff4948ac605447de7d.tar glibc-bb7cf681e90d5aa2d867aeff4948ac605447de7d.tar.gz glibc-bb7cf681e90d5aa2d867aeff4948ac605447de7d.tar.bz2 glibc-bb7cf681e90d5aa2d867aeff4948ac605447de7d.zip |
Preheat CPU in benchtests.
A benchmark could be skewed by CPU initialy working on minimal
frequency and speeding up later. We first run code in loop
to partialy fix this issue.
Diffstat (limited to 'benchtests')
-rw-r--r-- | benchtests/bench-skeleton.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/benchtests/bench-skeleton.c b/benchtests/bench-skeleton.c index 7359184ba8..a13ad02177 100644 --- a/benchtests/bench-skeleton.c +++ b/benchtests/bench-skeleton.c @@ -22,6 +22,21 @@ #include <time.h> #include <inttypes.h> +volatile unsigned int dontoptimize = 0; +void startup () +{ + /* This loop should cause CPU to switch to maximal freqency. + This makes subsequent measurement more accurate. We need a side effect + to prevent the loop being deleted by compiler. + This should be enough to cause CPU to speed up and it is simpler than + running loop for constant time. This is used when user does not have root + access to set a constant freqency. */ + + int k; + for (k = 0; k < 10000000; k++) + dontoptimize += 23 * dontoptimize + 2; +} + #define TIMESPEC_AFTER(a, b) \ (((a).tv_sec == (b).tv_sec) ? \ ((a).tv_nsec > (b).tv_nsec) : \ @@ -32,6 +47,8 @@ main (int argc, char **argv) unsigned long i, k; struct timespec start, end, runtime; + startup(); + memset (&runtime, 0, sizeof (runtime)); memset (&start, 0, sizeof (start)); memset (&end, 0, sizeof (end)); |