DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each bench.");
-DEFINE_int32(maxCalibrationAttempts, 3,
- "Try up to this many times to guess loops for a bench, or skip the bench.");
static SkString humanize(double ms) {
static int cpu_bench(const double overhead, Benchmark* bench, SkCanvas* canvas, double* samples) {
// First figure out approximately how many loops of bench it takes to make overhead negligible.
double bench_plus_overhead;
- int round = 0;
do {
bench_plus_overhead = time(1, bench, canvas, NULL);
- if (++round == FLAGS_maxCalibrationAttempts) {
- // At some point we have to just give up.
- return 0;
- }
} while (bench_plus_overhead < overhead);
// Later we'll just start and stop the timer once but loop N times.
fill_static_options(&log);
const double overhead = estimate_timer_overhead();
+ SkDebugf("Timer overhead: %s\n", humanize(overhead).c_str());
+
SkAutoTMalloc<double> samples(FLAGS_samples);
if (FLAGS_runOnce) {
*/
#include "SysTimer_windows.h"
+#include <intrin.h>
+
static ULONGLONG win_cpu_time() {
FILETIME createTime;
FILETIME exitTime;
return start_cpu_sys.QuadPart + start_cpu_usr.QuadPart;
}
-void SysTimer::startWall() {
- if (0 == ::QueryPerformanceCounter(&fStartWall)) {
- fStartWall.QuadPart = 0;
- }
-}
void SysTimer::startCpu() {
fStartCpu = win_cpu_time();
}
ULONGLONG end_cpu = win_cpu_time();
return static_cast<double>(end_cpu - fStartCpu) / 10000.0L;
}
+
+// On recent Intel chips (roughly, "has Core or Atom in its name") __rdtsc will always tick
+// at the CPU's maximum rate, even while power management clocks the CPU up and down.
+// That's great, because it makes measuring wall time super simple.
+
+void SysTimer::startWall() {
+ fStartWall = __rdtsc();
+}
+
double SysTimer::endWall() {
- LARGE_INTEGER end_wall;
- if (0 == ::QueryPerformanceCounter(&end_wall)) {
- end_wall.QuadPart = 0;
- }
+ unsigned __int64 end = __rdtsc();
- LARGE_INTEGER ticks_elapsed;
- ticks_elapsed.QuadPart = end_wall.QuadPart - fStartWall.QuadPart;
+ // This seems to, weirdly, give the CPU frequency in kHz. That's exactly what we want!
+ LARGE_INTEGER freq_khz;
+ QueryPerformanceFrequency(&freq_khz);
- LARGE_INTEGER frequency;
- if (0 == ::QueryPerformanceFrequency(&frequency)) {
- return 0.0L;
- } else {
- return static_cast<double>(ticks_elapsed.QuadPart)
- / static_cast<double>(frequency.QuadPart)
- * 1000.0L;
- }
+ return static_cast<double>(end - fStartWall) / static_cast<double>(freq_khz.QuadPart);
}