-
Notifications
You must be signed in to change notification settings - Fork 19
/
run.cpp
40 lines (36 loc) · 1.24 KB
/
run.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <benchmark/benchmark.h>
#include <hello_world.hpp>
static void BM_expensive(benchmark::State& state) // NOLINT google-runtime-references
{
if (state.thread_index == 0)
{
// Setup code here.
}
while (state.KeepRunning())
{
std::string value = hello_world::expensive(static_cast<std::size_t>(state.range(0)));
benchmark::DoNotOptimize(value.data());
benchmark::ClobberMemory();
}
if (state.thread_index == 0)
{
// Teardown code here.
}
}
static void BM_exclaim(benchmark::State& state) // NOLINT google-runtime-references
{
while (state.KeepRunning())
{
std::string value = hello_world::exclaim("hello");
benchmark::DoNotOptimize(value.data());
benchmark::ClobberMemory();
}
}
auto main(int argc, char* argv[]) -> int
{
benchmark::RegisterBenchmark("BM_exclaim", BM_exclaim)->Threads(2)->Threads(4)->Threads(8); // NOLINT clang-analyzer-cplusplus.NewDeleteLeaks
benchmark::RegisterBenchmark("BM_expensive", BM_expensive)->Threads(2)->Threads(4)->Threads(8)->Arg(1000000); // NOLINT clang-analyzer-cplusplus.NewDeleteLeaks
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
return 0;
}