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

Side by Side Diff: src/platform/microbenchmark/microbenchmark.cc

Issue 481009: Add a simple microbenchmark framework, packaging, and sample tests. (Closed)
Patch Set: fix the bad comment Created 11 years 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 | « src/platform/microbenchmark/microbenchmark.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 // Some portions Copyright (c) 2009 The Chromium Authors.
5
6 #include "microbenchmark/microbenchmark.h"
7
8 namespace chromeos {
9 // Commandline switch used to override the default number of runs for all
10 // tests.
11 const char *Microbenchmark::kRunsSwitch = "microbenchmark-runs";
12
13 void Microbenchmark::Run(uint64 number_of_runs) {
14 runs_ = number_of_runs;
15 Setup(number_of_runs);
16
17 uint64 current_run = runs_;
18 struct timespec start_time;
19 struct timespec stop_time;
20 // First we time the scaffolding.
21 clock_gettime(CLOCK_REALTIME, &start_time);
22 while (current_run--) {
23 SingleTest(true);
24 }
25 clock_gettime(CLOCK_REALTIME, &stop_time);
26 scaffold_total_ns_ +=
27 ((stop_time.tv_sec - start_time.tv_sec) * 1000000000ULL) +
28 (stop_time.tv_nsec - start_time.tv_nsec);
29 scaffold_per_run_ns_ = scaffold_total_ns_ / runs_;
30 // Now the real deal.
31 current_run = runs_;
32 clock_gettime(CLOCK_REALTIME, &start_time);
33 while (current_run--) {
34 SingleTest(false);
35 }
36 clock_gettime(CLOCK_REALTIME, &stop_time);
37 total_ns_ += ((stop_time.tv_sec - start_time.tv_sec) * 1000000000ULL) +
38 (stop_time.tv_nsec - start_time.tv_nsec);
39 per_run_ns_ = total_ns_ / runs_;
40 }
41
42 void Microbenchmark::Print() const {
43 LOG(WARNING) << "All measurements in nanoseconds";
44 LOG(WARNING) << "Numbers may overflow and may not be statistically "
45 << "meaningful.";
46 std::cout << "MB:name,runs,total_ns,per_run_ns\nMB:"
47 << name() << "-scaffold,"
48 << runs() << ","
49 << scaffold_total_nanoseconds() << ","
50 << scaffold_per_run_nanoseconds() << "\nMB:"
51 << name() << ","
52 << runs() << ","
53 << total_nanoseconds() << ","
54 << per_run_nanoseconds() << "\nMB:"
55 << name() << "-adjusted,"
56 << runs() << ","
57 << total_nanoseconds() - scaffold_total_nanoseconds() << ""
58 << per_run_nanoseconds() - scaffold_per_run_nanoseconds()
59 << "\n";
60 }
61
62 // Hide away helper functions here.
63 namespace microbenchmark_helper {
64 // Empty setup function.
65 void NoSetup(uint64) { }
66
67 } // namespace microbenchmark_helper
68 } // namespace chromeos
69
OLDNEW
« no previous file with comments | « src/platform/microbenchmark/microbenchmark.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698