37 if (gettimeofday(&tv, NULL) < 0)
38 Fatal(
"gettimeofday: %s", strerror(errno));
39 return (
int64_t)tv.tv_sec * 1000*1000 + tv.tv_usec;
48 int64_t LargeIntegerToInt64(
const LARGE_INTEGER& i) {
49 return ((
int64_t)i.HighPart) << 32 | i.LowPart;
53 LARGE_INTEGER counter;
54 if (!QueryPerformanceCounter(&counter))
55 Fatal(
"QueryPerformanceCounter: %s", GetLastErrorString().c_str());
56 return LargeIntegerToInt64(counter);
60 static int64_t ticks_per_sec = 0;
63 if (!QueryPerformanceFrequency(&freq))
64 Fatal(
"QueryPerformanceFrequency: %s", GetLastErrorString().c_str());
65 ticks_per_sec = LargeIntegerToInt64(freq);
69 return (dt * 1000000) / ticks_per_sec;
101 for (vector<Metric*>::iterator i =
metrics_.begin();
103 width = max((
int)(*i)->name.size(), width);
106 printf(
"%-*s\t%-6s\t%-9s\t%s\n", width,
107 "metric",
"count",
"avg (us)",
"total (ms)");
108 for (vector<Metric*>::iterator i =
metrics_.begin();
111 double total = metric->
sum / (double)1000;
112 double avg = metric->
sum / (double)metric->
count;
113 printf(
"%-*s\t%-6d\t%-8.1f\t%.1f\n", width, metric->
name.c_str(),
114 metric->
count, avg, total);
119 return TimerToMicros(HighResTimer());
123 return TimerToMicros(HighResTimer()) / 1000;