Skip to content

Commit 49cdc06

Browse files
committed
feat: add sleep benches
1 parent 16c0efb commit 49cdc06

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../google_benchmark_cmake/sleep_bench.hpp

examples/google_benchmark_cmake/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <cstring>
44

55
#include "fixture_bench.hpp"
6+
#include "sleep_bench.hpp"
67
#include "template_bench.hpp"
78

89
template <class... Args>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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

Comments
 (0)