1 #ifndef BENCHMARK_PERF_HELPERS_H
2 #define BENCHMARK_PERF_HELPERS_H
5 * Utility functions and constants used by perf tests.
12 * mmap an anonymous chunk of memory.
14 unsigned char *mmap_buffer(size_t size
);
16 * Returns a - b in microseconds.
19 uint64_t timespec_difference_us(const struct timespec
* a
, const struct timespec
* b
);
21 * Print the message to stdout along with the current time.
22 * Also flushes stdout so that the log can help detect hangs. Don't call
23 * this function from within the measured portion of the benchmark as it will
24 * pollute your measurement.
26 * NB: Will only log if verbose == true.
28 void benchmark_log(bool verbose
, const char *restrict fmt
, ...) __attribute__((format(printf
, 2, 3)));
30 static const uint64_t kNumMicrosecondsInSecond
= 1000UL * 1000;
31 static const uint64_t kNumNanosecondsInMicrosecond
= 1000UL;
32 static const uint64_t kNumNanosecondsInSecond
= kNumNanosecondsInMicrosecond
* kNumMicrosecondsInSecond
;
33 /* Get a (wall-time) timestamp in nanoseconds */
34 #define current_timestamp_ns() (clock_gettime_nsec_np(CLOCK_MONOTONIC_RAW));
38 #endif /* !defined(BENCHMARK_PERF_HELPERS_H) */