Commit 62288754 authored by Pádraig Ó Conbhuí's avatar Pádraig Ó Conbhuí
Browse files

Add benchmark with null-clock for pure PERForate timing

parent a7330f10
...@@ -29,6 +29,15 @@ static std::vector<size_t> to_measure() { ...@@ -29,6 +29,15 @@ static std::vector<size_t> to_measure() {
return value; return value;
} }
struct null_clock {
using rep = size_t;
using period = std::ratio<1, 1>;
using duration = std::chrono::duration<rep, period>;
using time_point = std::chrono::time_point<null_clock>;
static time_point now() { return time_point(std::chrono::seconds{0}); }
};
TEST_CASE("perforate::scoped_trace", "[scoped_trace][benchmark]") { TEST_CASE("perforate::scoped_trace", "[scoped_trace][benchmark]") {
BENCHMARK("std::chrono::high_resolution_clock::now()") { BENCHMARK("std::chrono::high_resolution_clock::now()") {
return std::chrono::high_resolution_clock::now(); return std::chrono::high_resolution_clock::now();
...@@ -36,6 +45,13 @@ TEST_CASE("perforate::scoped_trace", "[scoped_trace][benchmark]") { ...@@ -36,6 +45,13 @@ TEST_CASE("perforate::scoped_trace", "[scoped_trace][benchmark]") {
BENCHMARK("scoped_trace overhead") { PERFORATE_SCOPED_TRACE(nullptr); }; BENCHMARK("scoped_trace overhead") { PERFORATE_SCOPED_TRACE(nullptr); };
BENCHMARK("scoped_trace null clock overhead") {
auto s = perforate::scoped_trace<class tsc_tag, 0, null_clock>(nullptr);
return s;
};
BENCHMARK("null_clock::now()") { return null_clock::now(); };
// Measure the "PERFORATE_SCOPED_TRACE overhead to a loop with PERForate" // Measure the "PERFORATE_SCOPED_TRACE overhead to a loop with PERForate"
// Assume it's around 100ns. // Assume it's around 100ns.
{ {
...@@ -57,7 +73,7 @@ TEST_CASE("perforate::scoped_trace", "[scoped_trace][benchmark]") { ...@@ -57,7 +73,7 @@ TEST_CASE("perforate::scoped_trace", "[scoped_trace][benchmark]") {
// Outside loop // Outside loop
{ {
PERFORATE_SCOPED_TRACE("measuring work outside loop") PERFORATE_SCOPED_TRACE("measuring work outside loop")
.call_count(number_of_iterations); .call_count(number_of_iterations);
for (size_t i = 0; i < number_of_iterations; i++) { for (size_t i = 0; i < number_of_iterations; i++) {
use(to_measure()); use(to_measure());
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment