diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-09-21 03:48:23 +0000 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-09-21 03:48:23 +0000 |
commit | 5f446ac4c9d98c7819ff836c0666c798f351ae2c (patch) | |
tree | bdd7fa89e4241c1a3ced8ff4a7074d779df2a053 /src/sandglass.h | |
parent | 0b12bb29adc33255b97d2fb995ef145f0127d950 (diff) | |
download | libsandglass-5f446ac4c9d98c7819ff836c0666c798f351ae2c.tar.xz |
Make baseline calculations more accurate for SANDGLASS_REALTICKS.
Perform the baseline calculation directly in the sandglass_bench() macro, so
that the baseline is calculated in the same place (and therefore optimization
level, etc.) as the benchmarked code.
Diffstat (limited to 'src/sandglass.h')
-rw-r--r-- | src/sandglass.h | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/sandglass.h b/src/sandglass.h index 7073fb9..0d5e5e5 100644 --- a/src/sandglass.h +++ b/src/sandglass.h @@ -102,8 +102,12 @@ struct sandglass_t /* Adjustment to be added for negative (i.e. overflowed) grains counts */ long adjustment; - /* For SANDGLASS_TICKS looping support */ + /* For SANDGLASS_REALTICKS looping support */ unsigned int i, loops; + + /* A field used by sandglass_bench() to store the overhead of + sandglass_begin()/_elapse(), and of looping */ + long baseline; }; typedef struct sandglass_t sandglass_t; @@ -141,7 +145,23 @@ int sandglass_elapse(sandglass_t *sandglass); */ #define sandglass_bench(sandglass, routine) \ do { \ + /* Warm up the cache for these functions */ \ + sandglass_begin(sandglass); \ + sandglass_elapse(sandglass); \ + \ + /* Time an empty loop for our baseline */ \ + sandglass_begin(sandglass); \ + for ((sandglass)->i = 0; \ + (sandglass)->i < (sandglass)->loops; \ + ++(sandglass)->i) { \ + SANDGLASS_NO_UNROLL(); \ + } \ + sandglass_elapse(sandglass); \ + (sandglass)->baseline = (sandglass)->grains; \ + \ + /* Warm up the cache for our routine */ \ routine; \ + /* Time our routine in a loop */ \ sandglass_begin(sandglass); \ for ((sandglass)->i = 0; \ (sandglass)->i < (sandglass)->loops; \ @@ -150,6 +170,10 @@ int sandglass_elapse(sandglass_t *sandglass); routine; \ } \ sandglass_elapse(sandglass); \ + \ + /* Subtract the baseline and divide by the loop count */ \ + (sandglass)->grains -= (sandglass)->baseline; \ + (sandglass)->grains /= (sandglass)->loops; \ } while (0) #ifdef __cplusplus |