JayBeams  0.1
Another project to have fun coding.
microbenchmark_base.hpp
Go to the documentation of this file.
1 #ifndef jb_testing_microbenchmark_base_hpp
2 #define jb_testing_microbenchmark_base_hpp
3 
5 
6 #include <chrono>
7 #include <iostream>
8 #include <utility>
9 #include <vector>
10 
11 namespace jb {
12 namespace testing {
13 
14 /**
15  * Refactor non-template parts of the microbenchmark template class.
16  */
18 public:
19  typedef std::chrono::steady_clock clock;
20  typedef typename clock::duration duration;
21  typedef typename std::pair<int, duration> result;
22  typedef typename std::vector<result> results;
23 
24  /**
25  * Constructor from a configuration
26  */
28  : config_(cfg) {
29  }
30 
31  /**
32  * A simple object to contain the summary of the test results
33  */
34  struct summary {
36  : min(0)
37  , p25(0)
38  , p50(0)
39  , p75(0)
40  , p90(0)
41  , p99(0)
42  , p99_9(0)
43  , max(0)
44  , n(0) {
45  }
46  explicit summary(results const& arg);
47 
48  duration min;
49  duration p25;
50  duration p50;
51  duration p75;
52  duration p90;
53  duration p99;
54  duration p99_9;
55  duration max;
56  std::size_t n;
57  };
58 
59  /**
60  * Produce the results of the test in a format that works for most cases
61  *
62  * In most of the JayBeams tests we print the summary results to
63  * stderr and the summary results to stdout. That makes it
64  * relatively easy to capture both separately in driver scripts.
65  */
66  void typical_output(results const& r) const;
67 
68  /// Stream the detailed results
69  void write_results(std::ostream& os, results const& r) const;
70 
71 protected:
73 };
74 
75 /// Stream the summary of a microbenchmark results in microseconds
76 std::ostream&
77 operator<<(std::ostream& os, microbenchmark_base::summary const& x);
78 
79 } // namespace testing
80 } // namespace jb
81 
82 #endif // jb_testing_microbenchmark_base_hpp
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
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.
Refactor non-template parts of the microbenchmark template class.
void write_results(std::ostream &os, results const &r) const
Stream the detailed results.
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7
microbenchmark_base(microbenchmark_config const &cfg)
Constructor from a configuration.