Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: bench/nanobench.cpp

Issue 394363003: Use __rdtsc on Windows. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/Stats.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include <ctype.h> 8 #include <ctype.h>
9 9
10 #include "Benchmark.h" 10 #include "Benchmark.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 DEFINE_string(config, "nonrendering 8888 gpu", "Configs to measure. Options: " 43 DEFINE_string(config, "nonrendering 8888 gpu", "Configs to measure. Options: "
44 "565 8888 gpu nonrendering debug nullgpu msaa4 msaa16 nvprmsaa4 nv prmsaa16 angle"); 44 "565 8888 gpu nonrendering debug nullgpu msaa4 msaa16 nvprmsaa4 nv prmsaa16 angle");
45 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); 45 DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU.");
46 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag."); 46 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag.");
47 47
48 DEFINE_bool(cpu, true, "Master switch for CPU-bound work."); 48 DEFINE_bool(cpu, true, "Master switch for CPU-bound work.");
49 DEFINE_bool(gpu, true, "Master switch for GPU-bound work."); 49 DEFINE_bool(gpu, true, "Master switch for GPU-bound work.");
50 50
51 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); 51 DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
52 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each benc h."); 52 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each benc h.");
53 DEFINE_int32(maxCalibrationAttempts, 3,
54 "Try up to this many times to guess loops for a bench, or skip the bench.");
55 53
56 54
57 static SkString humanize(double ms) { 55 static SkString humanize(double ms) {
58 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); 56 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3);
59 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); 57 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6);
60 #ifdef SK_BUILD_FOR_WIN 58 #ifdef SK_BUILD_FOR_WIN
61 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); 59 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3);
62 #else 60 #else
63 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); 61 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3);
64 #endif 62 #endif
(...skipping 23 matching lines...) Expand all
88 double overhead = 0; 86 double overhead = 0;
89 for (int i = 0; i < FLAGS_overheadLoops; i++) { 87 for (int i = 0; i < FLAGS_overheadLoops; i++) {
90 overhead += time(1, NULL, NULL, NULL); 88 overhead += time(1, NULL, NULL, NULL);
91 } 89 }
92 return overhead / FLAGS_overheadLoops; 90 return overhead / FLAGS_overheadLoops;
93 } 91 }
94 92
95 static int cpu_bench(const double overhead, Benchmark* bench, SkCanvas* canvas, double* samples) { 93 static int cpu_bench(const double overhead, Benchmark* bench, SkCanvas* canvas, double* samples) {
96 // First figure out approximately how many loops of bench it takes to make o verhead negligible. 94 // First figure out approximately how many loops of bench it takes to make o verhead negligible.
97 double bench_plus_overhead; 95 double bench_plus_overhead;
98 int round = 0;
99 do { 96 do {
100 bench_plus_overhead = time(1, bench, canvas, NULL); 97 bench_plus_overhead = time(1, bench, canvas, NULL);
101 if (++round == FLAGS_maxCalibrationAttempts) {
102 // At some point we have to just give up.
103 return 0;
104 }
105 } while (bench_plus_overhead < overhead); 98 } while (bench_plus_overhead < overhead);
106 99
107 // Later we'll just start and stop the timer once but loop N times. 100 // Later we'll just start and stop the timer once but loop N times.
108 // We'll pick N to make timer overhead negligible: 101 // We'll pick N to make timer overhead negligible:
109 // 102 //
110 // overhead 103 // overhead
111 // ------------------------- < FLAGS_overheadGoal 104 // ------------------------- < FLAGS_overheadGoal
112 // overhead + N * Bench Time 105 // overhead + N * Bench Time
113 // 106 //
114 // where bench_plus_overhead ≈ overhead + Bench Time. 107 // where bench_plus_overhead ≈ overhead + Bench Time.
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 MultiResultsWriter log; 274 MultiResultsWriter log;
282 SkAutoTDelete<JSONResultsWriter> json; 275 SkAutoTDelete<JSONResultsWriter> json;
283 if (!FLAGS_outResultsFile.isEmpty()) { 276 if (!FLAGS_outResultsFile.isEmpty()) {
284 json.reset(SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0]))); 277 json.reset(SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0])));
285 log.add(json.get()); 278 log.add(json.get());
286 } 279 }
287 CallEnd<MultiResultsWriter> ender(log); 280 CallEnd<MultiResultsWriter> ender(log);
288 fill_static_options(&log); 281 fill_static_options(&log);
289 282
290 const double overhead = estimate_timer_overhead(); 283 const double overhead = estimate_timer_overhead();
284 SkDebugf("Timer overhead: %s\n", humanize(overhead).c_str());
285
291 SkAutoTMalloc<double> samples(FLAGS_samples); 286 SkAutoTMalloc<double> samples(FLAGS_samples);
292 287
293 if (FLAGS_runOnce) { 288 if (FLAGS_runOnce) {
294 SkDebugf("--runOnce is true; times would only be misleading so we won't print them.\n"); 289 SkDebugf("--runOnce is true; times would only be misleading so we won't print them.\n");
295 } else if (FLAGS_verbose) { 290 } else if (FLAGS_verbose) {
296 // No header. 291 // No header.
297 } else if (FLAGS_quiet) { 292 } else if (FLAGS_quiet) {
298 SkDebugf("median\tbench\tconfig\n"); 293 SkDebugf("median\tbench\tconfig\n");
299 } else { 294 } else {
300 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n"); 295 SkDebugf("loops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\ n");
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 } 372 }
378 373
379 return 0; 374 return 0;
380 } 375 }
381 376
382 #if !defined SK_BUILD_FOR_IOS 377 #if !defined SK_BUILD_FOR_IOS
383 int main(int argc, char * const argv[]) { 378 int main(int argc, char * const argv[]) {
384 return tool_main(argc, (char**) argv); 379 return tool_main(argc, (char**) argv);
385 } 380 }
386 #endif 381 #endif
OLDNEW
« no previous file with comments | « no previous file | tools/Stats.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698