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.
14
15#include "benchmark/reporter.h"
16#include "timers.h"
17
18#include <cstdlib>
19
20#include <iostream>
21#include <tuple>
22#include <vector>
23
24#include "check.h"
25#include "stat.h"
26
27namespace benchmark {
28
29BenchmarkReporter::BenchmarkReporter()
30    : output_stream_(&std::cout), error_stream_(&std::cerr) {}
31
32BenchmarkReporter::~BenchmarkReporter() {}
33
34void BenchmarkReporter::PrintBasicContext(std::ostream *out_ptr,
35                                          Context const &context) {
36  CHECK(out_ptr) << "cannot be null";
37  auto &Out = *out_ptr;
38
39  Out << "Run on (" << context.num_cpus << " X " << context.mhz_per_cpu
40      << " MHz CPU " << ((context.num_cpus > 1) ? "s" : "") << ")\n";
41
42  Out << LocalDateTimeString() << "\n";
43
44  if (context.cpu_scaling_enabled) {
45    Out << "***WARNING*** CPU scaling is enabled, the benchmark "
46           "real time measurements may be noisy and will incur extra "
47           "overhead.\n";
48  }
49
50#ifndef NDEBUG
51  Out << "***WARNING*** Library was built as DEBUG. Timings may be "
52         "affected.\n";
53#endif
54}
55
56double BenchmarkReporter::Run::GetAdjustedRealTime() const {
57  double new_time = real_accumulated_time * GetTimeUnitMultiplier(time_unit);
58  if (iterations != 0) new_time /= static_cast<double>(iterations);
59  return new_time;
60}
61
62double BenchmarkReporter::Run::GetAdjustedCPUTime() const {
63  double new_time = cpu_accumulated_time * GetTimeUnitMultiplier(time_unit);
64  if (iterations != 0) new_time /= static_cast<double>(iterations);
65  return new_time;
66}
67
68}  // end namespace benchmark
69