JayBeams  0.1
Another project to have fun coding.
microbenchmark_base.cpp
Go to the documentation of this file.
2 
3 #include <algorithm>
4 
6  summary s(r);
7  if (config_.test_case() != "") {
8  std::cerr << config_.test_case() << " ";
9  }
10  std::cerr << "summary ";
11  if (config_.size() != 0) {
12  std::cerr << "size=" << config_.size() << " ";
13  }
14  std::cerr << s << std::endl;
15  if (config_.verbose()) {
16  write_results(std::cout, r);
17  }
18 }
19 
21  std::ostream& os, results const& r) const {
22  bool all_sizes_are_zero = true;
23  for (auto const& v : r) {
24  if (v.first != 0) {
25  all_sizes_are_zero = false;
26  break;
27  }
28  }
29 
30  using namespace std::chrono;
31  if (all_sizes_are_zero) {
32  for (auto const& v : r) {
33  os << config_.prefix() << duration_cast<nanoseconds>(v.second).count()
34  << "\n";
35  }
36  } else {
37  for (auto const& v : r) {
38  os << config_.prefix() << v.first << ","
39  << duration_cast<nanoseconds>(v.second).count() << "\n";
40  }
41  }
42 }
43 
45  : summary() {
46  results r = arg;
47  auto cmp = [](result const& lhs, result const& rhs) {
48  return lhs.second < rhs.second;
49  };
50  std::sort(r.begin(), r.end(), cmp);
51  n = r.size();
52  auto p = [this, &r](double p) { return r[int(p * n / 100)].second; };
53  if (not r.empty()) {
54  min = p(0);
55  p25 = p(25);
56  p50 = p(50);
57  p75 = p(75);
58  p90 = p(90);
59  p99 = p(99);
60  p99_9 = p(99.9);
61  max = r.back().second;
62  }
63 }
64 
66  std::ostream& os, jb::testing::microbenchmark_base::summary const& x) {
67  using namespace std::chrono;
68  // Print the summary results in microseconds because they are often
69  return os << "min=" << duration_cast<microseconds>(x.min).count()
70  << "us, p25=" << duration_cast<microseconds>(x.p25).count()
71  << "us, p50=" << duration_cast<microseconds>(x.p50).count()
72  << "us, p75=" << duration_cast<microseconds>(x.p75).count()
73  << "us, p90=" << duration_cast<microseconds>(x.p90).count()
74  << "us, p99=" << duration_cast<microseconds>(x.p99).count()
75  << "us, p99.9=" << duration_cast<microseconds>(x.p99_9).count()
76  << "us, max=" << duration_cast<microseconds>(x.max).count()
77  << "us, N=" << x.n;
78 }
void typical_output(results const &r) const
Produce the results of the test in a format that works for most cases.
std::pair< int, duration > result
jb::config_attribute< microbenchmark_config, int > size
jb::config_attribute< microbenchmark_config, std::string > test_case
jb::config_attribute< microbenchmark_config, bool > verbose
std::ostream & operator<<(std::ostream &os, microbenchmark_base::summary const &x)
Stream the summary of a microbenchmark results in microseconds.
A simple object to contain the summary of the test results.
jb::config_attribute< microbenchmark_config, std::string > prefix
void write_results(std::ostream &os, results const &r) const
Stream the detailed results.