7#if defined(_MSC_VER) && (MSC_VER <= 1500)
8 #include <cybozu/inttype.hpp>
14#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__x86_64__)
15 #define CYBOZU_BENCH_USE_RDTSC
17#ifdef CYBOZU_BENCH_USE_RDTSC
22 #include <cybozu/time.hpp>
27#ifdef CYBOZU_BENCH_USE_RDTSC
35 unsigned int eax, edx;
36 __asm__
volatile(
"rdtsc" :
"=a"(eax),
"=d"(edx));
54 int getCount()
const {
return count_; }
56 void clear() { count_ = 0; clock_ = 0; }
57 void put(
const char *msg = 0,
int N = 1)
const
60 if (msg && *msg) printf(
"%s ", msg);
62 printf(
"%7.3fMclk", t * 1e-6);
64 printf(
"%7.3fKclk", t * 1e-3);
66 printf(
"%6.2f clk", t);
68 if (msg && *msg) printf(
"\n");
71 static const int loopN1 = 1000;
72 static const int loopN2 = 1000000;
84 CpuClock() : clock_(0), count_(0) { t_.setTime(0, 0); }
87 if (count_ == 0) t_.setCurrentTime();
94 cybozu::Time cur(
true);
95 int diffSec = (int)(cur.getTime() - t_.getTime());
96 int diffMsec = cur.getMsec() - t_.getMsec();
97 const int diff = diffSec * 1000 + diffMsec;
103 void clear() { t_.setTime(0, 0); clock_ = 0; count_ = 0; }
104 void put(
const char *msg = 0,
int N = 1)
const
107 if (msg && *msg) printf(
"%s ", msg);
109 printf(
"%6.2fmsec", t);
110 }
else if (t > 1e-3) {
111 printf(
"%6.2fusec", t * 1e3);
113 printf(
"%6.2fnsec", t * 1e6);
115 if (msg && *msg) printf(
"\n");
128 #define CYBOZU_UNUSED __attribute__((unused))
130 #define CYBOZU_UNUSED
140#define CYBOZU_BENCH(msg, func, ...) \
142 const uint64_t maxClk = cybozu::CpuClock::maxClk; \
143 cybozu::CpuClock clk; \
144 for (int i = 0; i < cybozu::CpuClock::loopN2; i++) { \
146 for (int j = 0; j < cybozu::CpuClock::loopN1; j++) { func(__VA_ARGS__); } \
148 if (clk.getClock() > maxClk) break; \
150 if (msg && *msg) clk.put(msg, cybozu::CpuClock::loopN1); \
151 cybozu::bench::g_clk = clk; cybozu::bench::g_loopNum = cybozu::CpuClock::loopN1; \
159#define CYBOZU_BENCH_C(msg, _N, func, ...) \
161 cybozu::CpuClock clk; \
163 for (int j = 0; j < _N; j++) { func(__VA_ARGS__); } \
165 if (msg && *msg) clk.put(msg, _N); \
166 cybozu::bench::g_clk = clk; cybozu::bench::g_loopNum = _N; \
void put(const char *msg=0, int N=1) const
static const uint64_t maxClk
uint64_t getClock() const
void diff(const std::string &a, const std::string &b)
unsigned __int64 uint64_t