90d6f8bf62
libglim is an Apache-licensed C++ wrapper for lmdb, and rather than rolling our own it seems prudent to use it. Note: lmdb is not included in it, and unless something happens as did with libunbound, should be installed via each OS' package manager or equivalent.
32 lines
837 B
C++
32 lines
837 B
C++
#ifndef _TSC_TIMER_H
|
|
#define _TSC_TIMER_H
|
|
|
|
namespace glim {
|
|
|
|
extern "C" { // http://en.wikipedia.org/wiki/Rdtsc
|
|
#if (defined(__GNUC__) || defined(__ICC)) && defined(__i386__)
|
|
static __inline__ unsigned long long rdTsc(void) {
|
|
unsigned long long ret;
|
|
__asm__ __volatile__("rdtsc": "=A" (ret));
|
|
return ret;
|
|
}
|
|
#elif (defined(__GNUC__) || defined(__ICC) || defined(__SUNPRO_C)) && defined(__x86_64__)
|
|
static __inline__ unsigned long long rdTsc(void) {
|
|
unsigned a, d;
|
|
asm volatile("rdtsc" : "=a" (a), "=d" (d));
|
|
return ((unsigned long long)a) | (((unsigned long long)d) << 32);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
//! CPU cycles timer. Fast, not safe.
|
|
//! cf. http://en.wikipedia.org/wiki/Rdtsc
|
|
struct TscTimer {
|
|
int64_t start;
|
|
TscTimer (): start (rdTsc()) {}
|
|
int64_t operator()() const {return rdTsc() - start;}
|
|
};
|
|
|
|
}
|
|
|
|
#endif // _TSC_TIMER_H
|