summaryrefslogtreecommitdiffstats
path: root/loop.cc
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2013-08-20 12:59:09 -0400
committerErik Schnetter <schnetter@gmail.com>2013-08-20 12:59:09 -0400
commite00507b552f6fb4fa48e3ba083e480cb9c049694 (patch)
tree0a4173ef3d8fe68f961d2e14991b747148b2e085 /loop.cc
parente55b50d9a712087a5cfc8b7a863765d081535389 (diff)
downloadvecmathlib-e00507b552f6fb4fa48e3ba083e480cb9c049694.zip
vecmathlib-e00507b552f6fb4fa48e3ba083e480cb9c049694.tar.gz
Use better timers for benchmarking loops
Diffstat (limited to 'loop.cc')
-rw-r--r--loop.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/loop.cc b/loop.cc
index b64d9a4..ca8ebb8 100644
--- a/loop.cc
+++ b/loop.cc
@@ -41,12 +41,11 @@ inline ticks getticks()
{
#if __has_builtin(__builtin_readcyclecounter)
return __builtin_readcyclecounter();
-#else
-# if defined __x86_64__
+#elif defined __x86_64__
ticks a, d;
asm volatile("rdtsc" : "=a" (a), "=d" (d));
return a | (d << 32);
-# elif defined __powerpc__
+#elif defined __powerpc__
unsigned int tbl, tbu, tbu1;
do {
asm volatile("mftbu %0": "=r"(tbu));
@@ -54,7 +53,13 @@ inline ticks getticks()
asm volatile("mftbu %0": "=r"(tbu1));
} while (tbu != tbu1);
return ((unsigned long long)tbu << 32) | tbl;
-# endif
+#else
+ timeval tv;
+ gettimeofday(&tv, NULL);
+ return 1000000ULL * tv.tv_sec + tv.tv_usec;
+ // timespec ts;
+ // clock_gettime(CLOCK_REALTIME, &ts);
+ // return 1000000000ULL * ts.tv_sec + ts.tv_nsec;
#endif
}
inline double elapsed(ticks t1, ticks t0)
OpenPOWER on IntegriCloud