Skip to content

Commit c72ce91

Browse files
feat: add google_benchmark example
1 parent 2bdf7d9 commit c72ce91

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
cmake_minimum_required(VERSION 3.12)
2+
include(FetchContent)
3+
4+
project(
5+
codspeed_picobench_compat
6+
VERSION 0.0.0
7+
LANGUAGES CXX)
8+
9+
set(BENCHMARK_DOWNLOAD_DEPENDENCIES ON)
10+
11+
# FetchContent_Declare( google_benchmark GIT_REPOSITORY
12+
# https://github.com/CodSpeedHQ/codspeed-cpp GIT_TAG
13+
# origin/cod-291-implement-the-core-instrumentation-library-in-c SOURCE_SUBDIR
14+
# google_benchmark)
15+
16+
FetchContent_Declare(google_benchmark
17+
SOURCE_DIR ${CMAKE_SOURCE_DIR}/../../google_benchmark)
18+
19+
FetchContent_MakeAvailable(google_benchmark)
20+
21+
add_executable(benchmark_example main.cpp)
22+
23+
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)