|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#include <benchmark/benchmark.h> |
| 4 | + |
| 5 | +#include <chrono> |
| 6 | +#include <thread> |
| 7 | + |
| 8 | +static void BM_sleep_1ns(benchmark::State& state) { |
| 9 | + for (auto _ : state) { |
| 10 | + std::this_thread::sleep_for(std::chrono::nanoseconds(1)); |
| 11 | + } |
| 12 | +} |
| 13 | +BENCHMARK(BM_sleep_1ns); |
| 14 | + |
| 15 | +static void BM_sleep_100ns(benchmark::State& state) { |
| 16 | + for (auto _ : state) { |
| 17 | + std::this_thread::sleep_for(std::chrono::nanoseconds(100)); |
| 18 | + } |
| 19 | +} |
| 20 | +BENCHMARK(BM_sleep_100ns); |
| 21 | + |
| 22 | +static void BM_sleep_1us(benchmark::State& state) { |
| 23 | + for (auto _ : state) { |
| 24 | + std::this_thread::sleep_for(std::chrono::microseconds(1)); |
| 25 | + } |
| 26 | +} |
| 27 | +BENCHMARK(BM_sleep_1us); |
| 28 | + |
| 29 | +static void BM_sleep_100us(benchmark::State& state) { |
| 30 | + for (auto _ : state) { |
| 31 | + std::this_thread::sleep_for(std::chrono::microseconds(100)); |
| 32 | + } |
| 33 | +} |
| 34 | +BENCHMARK(BM_sleep_100us); |
| 35 | + |
| 36 | +static void BM_sleep_1ms(benchmark::State& state) { |
| 37 | + for (auto _ : state) { |
| 38 | + std::this_thread::sleep_for(std::chrono::milliseconds(1)); |
| 39 | + } |
| 40 | +} |
| 41 | +BENCHMARK(BM_sleep_1ms); |
| 42 | + |
| 43 | +static void BM_sleep_10ms(benchmark::State& state) { |
| 44 | + for (auto _ : state) { |
| 45 | + std::this_thread::sleep_for(std::chrono::milliseconds(10)); |
| 46 | + } |
| 47 | +} |
| 48 | +BENCHMARK(BM_sleep_10ms); |
| 49 | + |
| 50 | +static void BM_sleep_50ms(benchmark::State& state) { |
| 51 | + for (auto _ : state) { |
| 52 | + std::this_thread::sleep_for(std::chrono::milliseconds(50)); |
| 53 | + } |
| 54 | +} |
| 55 | +BENCHMARK(BM_sleep_50ms); |
| 56 | + |
| 57 | +static void BM_sleep_100ms(benchmark::State& state) { |
| 58 | + for (auto _ : state) { |
| 59 | + std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 60 | + } |
| 61 | +} |
| 62 | +BENCHMARK(BM_sleep_100ms); |
0 commit comments