Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/google_benchmark_cmake/fixture_bench.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ class MyFixture : public benchmark::Fixture {
};
BENCHMARK_F(MyFixture, FooTest)(benchmark::State &st) {
for (auto _ : st) {
benchmark::ClobberMemory();
}
}
BENCHMARK_DEFINE_F(MyFixture, BarTest)(benchmark::State &st) {
for (auto _ : st) {
benchmark::ClobberMemory();
}
}
BENCHMARK_REGISTER_F(MyFixture, BarTest);
Expand All @@ -31,11 +33,13 @@ template <typename T>
class MyTemplatedFixture : public benchmark::Fixture {};
BENCHMARK_TEMPLATE_F(MyTemplatedFixture, IntTest, int)(benchmark::State &st) {
for (auto _ : st) {
benchmark::ClobberMemory();
}
}
BENCHMARK_TEMPLATE_DEFINE_F(MyTemplatedFixture, DoubleTest,
double)(benchmark::State &st) {
for (auto _ : st) {
benchmark::ClobberMemory();
}
}
BENCHMARK_REGISTER_F(MyTemplatedFixture, DoubleTest);
Expand All @@ -47,6 +51,7 @@ template <typename T>
class MyTemplate1 : public benchmark::Fixture {};
BENCHMARK_TEMPLATE1_DEFINE_F(MyTemplate1, TestA, int)(benchmark::State &st) {
for (auto _ : st) {
benchmark::ClobberMemory();
}
}
BENCHMARK_REGISTER_F(MyTemplate1, TestA);
Expand All @@ -59,6 +64,7 @@ class MyTemplate2 : public benchmark::Fixture {};
BENCHMARK_TEMPLATE2_DEFINE_F(MyTemplate2, TestB, int,
double)(benchmark::State &st) {
for (auto _ : st) {
benchmark::ClobberMemory();
}
}
BENCHMARK_REGISTER_F(MyTemplate2, TestB);
Expand Down
13 changes: 11 additions & 2 deletions examples/google_benchmark_cmake/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
template <class... Args>
void BM_Capture(benchmark::State &state, Args &&...args) {
auto args_tuple = std::make_tuple(std::move(args)...);
(void)args_tuple;
for (auto _ : state) {
benchmark::DoNotOptimize(args_tuple);
benchmark::ClobberMemory();
}
}
BENCHMARK_CAPTURE(BM_Capture, int_string_test, 42, std::string("abc"));
Expand All @@ -20,6 +21,8 @@ static void BM_rand_vector(benchmark::State &state) {
std::vector<int> v;
for (auto _ : state) {
std::string empty_string;
benchmark::DoNotOptimize(empty_string);
benchmark::ClobberMemory();
}
}
// Register the function as a benchmark
Expand All @@ -30,6 +33,8 @@ static void BM_StringCopy(benchmark::State &state) {
std::string x = "hello";
for (auto _ : state) {
std::string copy(x);
benchmark::DoNotOptimize(copy);
benchmark::ClobberMemory();
}
}
// Register the function as a benchmark
Expand All @@ -39,7 +44,11 @@ static void BM_memcpy(benchmark::State &state) {
char *src = new char[state.range(0)];
char *dst = new char[state.range(0)];
memset(src, 'x', state.range(0));
for (auto _ : state) memcpy(dst, src, state.range(0));
for (auto _ : state) {
memcpy(dst, src, state.range(0));
benchmark::DoNotOptimize(dst);
benchmark::ClobberMemory();
}
delete[] src;
delete[] dst;
}
Expand Down
4 changes: 4 additions & 0 deletions examples/google_benchmark_cmake/template_bench.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ template <class T> void BM_Template(benchmark::State &state) {
std::vector<T> v;
for (auto _ : state) {
v.push_back(T());
benchmark::DoNotOptimize(v);
benchmark::ClobberMemory();
}
}
BENCHMARK_TEMPLATE(BM_Template, int);
Expand Down Expand Up @@ -46,6 +48,8 @@ template <typename T, class... ExtraArgs>
void BM_Template1_Capture(benchmark::State &state, ExtraArgs &&...extra_args) {
auto args_tuple = std::make_tuple(std::move(extra_args)...);
for (auto _ : state) {
benchmark::DoNotOptimize(args_tuple);
benchmark::ClobberMemory();
}
}
BENCHMARK_TEMPLATE1_CAPTURE(BM_Template1_Capture, void, int_string_test, 42,
Expand Down