75 lines
1.4 KiB
C++
75 lines
1.4 KiB
C++
|
#include "tile/base/chrono.h"
|
||
|
|
||
|
#include <sys/time.h>
|
||
|
|
||
|
#include <chrono>
|
||
|
|
||
|
#include "benchmark/benchmark.h"
|
||
|
|
||
|
namespace tile {
|
||
|
|
||
|
void
|
||
|
Benchmark_GetTimeOfDay(benchmark::State &state)
|
||
|
{
|
||
|
while (state.KeepRunning()) {
|
||
|
struct timeval tv;
|
||
|
gettimeofday(&tv, nullptr);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
BENCHMARK(Benchmark_GetTimeOfDay);
|
||
|
|
||
|
void
|
||
|
Benchmark_StdSteadyClock(benchmark::State &state)
|
||
|
{
|
||
|
while (state.KeepRunning()) { (void) std::chrono::steady_clock::now(); }
|
||
|
}
|
||
|
|
||
|
BENCHMARK(Benchmark_StdSteadyClock);
|
||
|
|
||
|
void
|
||
|
Benchmark_StdSystemClock(benchmark::State &state)
|
||
|
{
|
||
|
while (state.KeepRunning()) { (void) std::chrono::system_clock::now(); }
|
||
|
}
|
||
|
|
||
|
BENCHMARK(Benchmark_StdSystemClock);
|
||
|
|
||
|
void
|
||
|
Benchmark_ReadSteadyClock(benchmark::State &state)
|
||
|
{
|
||
|
while (state.KeepRunning()) { ReadSteadyClock(); }
|
||
|
}
|
||
|
|
||
|
BENCHMARK(Benchmark_ReadSteadyClock);
|
||
|
|
||
|
void
|
||
|
Benchmark_ReadSystemClock(benchmark::State &state)
|
||
|
{
|
||
|
while (state.KeepRunning()) { ReadSystemClock(); }
|
||
|
}
|
||
|
|
||
|
BENCHMARK(Benchmark_ReadSystemClock);
|
||
|
|
||
|
void
|
||
|
Benchmark_ReadCoarseSteadyClock(benchmark::State &state)
|
||
|
{
|
||
|
while (state.KeepRunning()) {
|
||
|
// ... <+23>: lea 0x137c5a(%rip),%rax # `system_clock_time_since_epoch`
|
||
|
// ... <+30>: mov (%rax),%rax
|
||
|
ReadCoarseSteadyClock();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
BENCHMARK(Benchmark_ReadCoarseSteadyClock);
|
||
|
|
||
|
void
|
||
|
Benchmark_ReadCoarseSystemClock(benchmark::State &state)
|
||
|
{
|
||
|
while (state.KeepRunning()) { ReadCoarseSystemClock(); }
|
||
|
}
|
||
|
|
||
|
BENCHMARK(Benchmark_ReadCoarseSystemClock);
|
||
|
|
||
|
}// namespace tile
|