1 // Copyright 2015 Google Inc. All rights reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #include "benchmark/benchmark.h"
28 BenchmarkReporter::BenchmarkReporter()
29 : output_stream_(&std::cout
), error_stream_(&std::cerr
) {}
31 BenchmarkReporter::~BenchmarkReporter() {}
33 void BenchmarkReporter::PrintBasicContext(std::ostream
*out
,
34 Context
const &context
) {
35 CHECK(out
) << "cannot be null";
38 Out
<< LocalDateTimeString() << "\n";
40 if (context
.executable_name
)
41 Out
<< "Running " << context
.executable_name
<< "\n";
43 const CPUInfo
&info
= context
.cpu_info
;
44 Out
<< "Run on (" << info
.num_cpus
<< " X "
45 << (info
.cycles_per_second
/ 1000000.0) << " MHz CPU "
46 << ((info
.num_cpus
> 1) ? "s" : "") << ")\n";
47 if (info
.caches
.size() != 0) {
48 Out
<< "CPU Caches:\n";
49 for (auto &CInfo
: info
.caches
) {
50 Out
<< " L" << CInfo
.level
<< " " << CInfo
.type
<< " "
51 << (CInfo
.size
/ 1000) << "K";
52 if (CInfo
.num_sharing
!= 0)
53 Out
<< " (x" << (info
.num_cpus
/ CInfo
.num_sharing
) << ")";
58 if (info
.scaling_enabled
) {
59 Out
<< "***WARNING*** CPU scaling is enabled, the benchmark "
60 "real time measurements may be noisy and will incur extra "
65 Out
<< "***WARNING*** Library was built as DEBUG. Timings may be "
70 // No initializer because it's already initialized to NULL.
71 const char* BenchmarkReporter::Context::executable_name
;
73 BenchmarkReporter::Context::Context() : cpu_info(CPUInfo::Get()) {}
75 double BenchmarkReporter::Run::GetAdjustedRealTime() const {
76 double new_time
= real_accumulated_time
* GetTimeUnitMultiplier(time_unit
);
77 if (iterations
!= 0) new_time
/= static_cast<double>(iterations
);
81 double BenchmarkReporter::Run::GetAdjustedCPUTime() const {
82 double new_time
= cpu_accumulated_time
* GetTimeUnitMultiplier(time_unit
);
83 if (iterations
!= 0) new_time
/= static_cast<double>(iterations
);
87 } // end namespace benchmark