[MIParser] Set RegClassOrRegBank during instruction parsing
[llvm-complete.git] / utils / benchmark / src / reporter.cc
blob4b40aaec8b94d20c7f6e78f19042833dbead6673
1 // Copyright 2015 Google Inc. All rights reserved.
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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"
16 #include "timers.h"
18 #include <cstdlib>
20 #include <iostream>
21 #include <tuple>
22 #include <vector>
24 #include "check.h"
26 namespace benchmark {
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";
36 auto &Out = *out;
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) << ")";
54 Out << "\n";
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 "
61 "overhead.\n";
64 #ifndef NDEBUG
65 Out << "***WARNING*** Library was built as DEBUG. Timings may be "
66 "affected.\n";
67 #endif
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);
78 return new_time;
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);
84 return new_time;
87 } // end namespace benchmark