add a benchmark for standard std::chrono clocks

Summary:
Querying clocks has a cost. Add a microbenchmark for measuring that
cost on all platforms.

Reviewed By: genevievehelsel

Differential Revision: D42182073

fbshipit-source-id: facb907fc4abed74625e0e28fe3ab63d8335a9fd
This commit is contained in:
Chad Austin 2022-12-21 14:44:54 -08:00 committed by Facebook GitHub Bot
parent d934cb3715
commit f0e16a3f02

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include <chrono>
#include "eden/common/utils/benchharness/Bench.h"
namespace {
using namespace benchmark;
using namespace facebook::eden;
void system_clock(benchmark::State& state) {
for (auto _ : state) {
benchmark::DoNotOptimize(std::chrono::system_clock::now());
}
}
BENCHMARK(system_clock);
void steady_clock(benchmark::State& state) {
for (auto _ : state) {
benchmark::DoNotOptimize(std::chrono::steady_clock::now());
}
}
BENCHMARK(steady_clock);
void high_resolution_clock(benchmark::State& state) {
for (auto _ : state) {
benchmark::DoNotOptimize(std::chrono::high_resolution_clock::now());
}
}
BENCHMARK(high_resolution_clock);
} // namespace