1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#ifndef _BENCHMARK_H_
#define _BENCHMARK_H_
#include "event_counter.h"
/*
* Prints the best number of operations per cycle where
* test is the function call, answer is the expected answer generated by
* test, repeat is the number of times we should repeat and size is the
* number of operations represented by test.
*/
#define BEST_TIME(name, test, expected, pre, repeat, size, verbose) \
do { \
if (verbose) \
std::printf("%-40s\t: ", name); \
else \
std::printf("\"%-40s\"", name); \
fflush(NULL); \
event_collector collector; \
event_aggregate aggregate{}; \
for (decltype(repeat) i = 0; i < repeat; i++) { \
pre; \
std::atomic_thread_fence(std::memory_order_acquire); \
collector.start(); \
if (test != expected) { \
std::fprintf(stderr, "not expected (%d , %d )", (int)test, \
(int)expected); \
break; \
} \
std::atomic_thread_fence(std::memory_order_release); \
event_count allocate_count = collector.end(); \
aggregate << allocate_count; \
} \
if (collector.has_events()) { \
std::printf("%7.3f", \
aggregate.best.cycles() / static_cast<double>(size)); \
if (verbose) { \
std::printf(" cycles/byte "); \
} \
std::printf("\t"); \
std::printf("%7.3f", \
aggregate.best.instructions() / static_cast<double>(size)); \
if (verbose) { \
std::printf(" instructions/byte "); \
} \
std::printf("\t"); \
} \
double gb = static_cast<double>(size) / 1000000000.0; \
std::printf("%7.3f", gb / aggregate.best.elapsed_sec()); \
if (verbose) { \
std::printf(" GB/s "); \
} \
std::printf("\t"); \
std::printf("%7.3f", 1.0 / aggregate.best.elapsed_sec()); \
if (verbose) { \
std::printf(" documents/s "); \
} \
std::printf("\n"); \
std::fflush(NULL); \
} while (0)
// like BEST_TIME, but no check
#define BEST_TIME_NOCHECK(name, test, pre, repeat, size, verbose) \
do { \
if (verbose) \
std::printf("%-40s\t: ", name); \
else \
std::printf("\"%-40s\"", name); \
std::fflush(NULL); \
event_collector collector; \
event_aggregate aggregate{}; \
for (decltype(repeat) i = 0; i < repeat; i++) { \
pre; \
std::atomic_thread_fence(std::memory_order_acquire); \
collector.start(); \
test; \
std::atomic_thread_fence(std::memory_order_release); \
event_count allocate_count = collector.end(); \
aggregate << allocate_count; \
} \
if (collector.has_events()) { \
std::printf("%7.3f", \
aggregate.best.cycles() / static_cast<double>(size)); \
if (verbose) { \
std::printf(" cycles/byte "); \
} \
std::printf("\t"); \
std::printf("%7.3f", \
aggregate.best.instructions() / static_cast<double>(size)); \
if (verbose) { \
std::printf(" instructions/byte "); \
} \
std::printf("\t"); \
} \
double gb = static_cast<double>(size) / 1000000000.0; \
std::printf("%7.3f", gb / aggregate.best.elapsed_sec()); \
if (verbose) { \
std::printf(" GB/s "); \
} \
std::printf("\t"); \
std::printf("%7.3f", 1.0 / aggregate.best.elapsed_sec()); \
if (verbose) { \
std::printf(" documents/s "); \
} \
std::printf("\n"); \
std::fflush(NULL); \
} while (0)
#endif
|