Skip to content

Commit ef01d2a

Browse files
feat(google_benchmark): add google_benchmark example
1 parent db44326 commit ef01d2a

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
include(FetchContent)
3+
4+
project(codspeed_picobench_compat VERSION 0.0.0 LANGUAGES CXX)
5+
6+
set(BENCHMARK_DOWNLOAD_DEPENDENCIES ON)
7+
8+
FetchContent_Declare(
9+
google_benchmark
10+
SOURCE_DIR
11+
${CMAKE_SOURCE_DIR}/../../google_benchmark
12+
)
13+
14+
FetchContent_MakeAvailable(google_benchmark)
15+
16+
add_executable(benchmark_example main.cpp)
17+
18+
target_link_libraries(benchmark_example benchmark::benchmark)

examples/google_benchmark/main.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <benchmark/benchmark.h>
2+
3+
// Function to benchmark
4+
static void BM_rand_vector(benchmark::State &state) {
5+
std::vector<int> v;
6+
for (auto _ : state) {
7+
std::string empty_string;
8+
}
9+
}
10+
// Register the function as a benchmark
11+
BENCHMARK(BM_rand_vector);
12+
13+
// Function to benchmark with a parameter
14+
static void BM_StringCopy(benchmark::State &state) {
15+
std::string x = "hello";
16+
for (auto _ : state) {
17+
std::string copy(x);
18+
}
19+
}
20+
// Register the function as a benchmark
21+
BENCHMARK(BM_StringCopy);
22+
23+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)