File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
examples/google_benchmark Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 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)
Original file line number Diff line number Diff line change 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 ();
You can’t perform that action at this time.
0 commit comments