aboutsummaryrefslogtreecommitdiffstats
path: root/checks/clock.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-05-18 18:33:19 +0000
committerlloyd <[email protected]>2006-05-18 18:33:19 +0000
commita2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch)
treead3d6c4fcc8dd0f403f8105598943616246fe172 /checks/clock.cpp
Initial checkin1.5.6
Diffstat (limited to 'checks/clock.cpp')
-rw-r--r--checks/clock.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/checks/clock.cpp b/checks/clock.cpp
new file mode 100644
index 000000000..02ef431bd
--- /dev/null
+++ b/checks/clock.cpp
@@ -0,0 +1,58 @@
+#include <botan/botan.h>
+using namespace Botan;
+
+#include "common.h"
+#include <time.h>
+
+/*
+ Using clock() or similiar is bad news when using a hardware-based Engine,
+ as all the stuff is offloaded and we use zero CPU time, which makes the
+ benchmarks and such take forever.
+*/
+
+#define USE_CLOCK 1
+#define USE_TIMES 0
+#define USE_POSIX_GETTIME 0
+#define USE_RDTSC 0
+
+/* If using USE_RDTSC, set to your CPU's Mhz */
+#define CPU_MHZ 1333
+
+#if USE_CLOCK
+
+ u64bit get_clock() { return clock(); }
+ u64bit get_ticks() { return CLOCKS_PER_SEC; }
+
+#elif USE_TIMES
+
+ #include <sys/times.h>
+ #include <unistd.h>
+ u64bit get_clock() { return times(0); }
+ u64bit get_ticks() { return sysconf(_SC_CLK_TCK); }
+
+#elif USE_POSIX_GETTIME
+
+u64bit get_clock()
+ {
+ struct timespec tv;
+ clock_gettime(CLOCK_REALTIME, &tv);
+
+ return (tv.tv_sec * 1000000000 + tv.tv_nsec) / 1000;
+ }
+
+u64bit get_ticks() { return 1000000; }
+#elif USE_RDTSC
+
+ u64bit get_clock()
+ {
+ u64bit rtc = 0;
+ u32bit rtc_low = 0, rtc_high = 0;
+ asm volatile("rdtsc" : "=d" (rtc_high), "=a" (rtc_low));
+ rtc = ((u64bit)rtc_high << 32) | rtc_low;
+ return rtc / 1000;
+ }
+
+ u64bit get_ticks() { return CPU_MHZ * 1000; }
+#else
+ #error "Must choose a timing method!"
+#endif