17 int main(
int argc,
char* argv[]) {
18 auto testcases = create_testcases();
30 #ifndef JB_DEFAULTS_clock_repetitions 31 #define JB_DEFAULTS_clock_repetitions 1000 32 #endif // JB_DEFAULTS_clock_repetitions 42 template <
typename clock_type>
46 : fixture(defaults::clock_repetitions) {
49 explicit fixture(
int size)
50 : calls_per_iteration_(size) {
54 for (
int i = 0; i != calls_per_iteration_; ++i) {
55 (void)clock_type::now();
57 return calls_per_iteration_;
61 int calls_per_iteration_;
65 struct wrapped_rtdscp {
66 static std::uint64_t now() {
69 __asm__ __volatile__(
"rdtscp\n" :
"=a"(lo),
"=d"(hi),
"=c"(aux) : :);
70 return (hi << 32) + lo;
75 struct wrapped_rtdsc {
76 static std::uint64_t now() {
79 __asm__ __volatile__(
"rdtsc\n" :
"=a"(lo),
"=d"(hi),
"=c"(aux) : :);
80 return (hi << 32) + lo;
84 template <
typename clock_type>
85 std::function<void(config const&)> test_case() {
86 return [](config
const& cfg) {
95 using namespace std::chrono;
97 {
"std::chrono::steady_clock", test_case<steady_clock>()},
98 {
"std::chrono::high_resolution_clock",
99 test_case<high_resolution_clock>()},
100 {
"std::chrono::system_clock_clock", test_case<system_clock>()},
101 {
"rdtscp", test_case<wrapped_rtdscp>()},
102 {
"rdtsc", test_case<wrapped_rtdsc>()},
Define defaults for program parameters.
int microbenchmark_group_main(int argc, char *argv[], microbenchmark_group< microbenchmark_config > const &testcases)
Overload microbenchmark_group_main for jb::testing::microbenchmark_config.
std::map< std::string, std::function< void(config const &cfg)> > microbenchmark_group
Define a representation for a group of microbenchmarks.
Configure a micro-benchmark.
int main(int argc, char *argv[])
Run a micro-benchmark on a given class.
#define JB_DEFAULTS_clock_repetitions