File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
examples/google_benchmark Expand file tree Collapse file tree 2 files changed +46
-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 (
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)
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