File tree Expand file tree Collapse file tree 4 files changed +82
-0
lines changed
include/codspeed_picobench_compat Expand file tree Collapse file tree 4 files changed +82
-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_google_benchmark_compat VERSION 0.0.0 LANGUAGES CXX)
5+
6+ FetchContent_Declare(
7+ google_benchmark
8+ GIT_REPOSITORY https://github.com/google/benchmark.git
9+ GIT_TAG 12235e24652fc7f809373e7c11a5f73c5763fc4c # v1.9.0
10+ )
11+ FetchContent_MakeAvailable(google_benchmark)
12+
13+ add_library (codspeed_picobench_compat)
14+
Original file line number Diff line number Diff line change 1+ macro (pb_example name )
2+ set (tgt picobench-example-${name} )
3+ add_executable (${tgt} ${ARGN} )
4+ target_link_libraries (${tgt} codspeed_picobench_compat)
5+ set_target_properties (${tgt} PROPERTIES FOLDER example)
6+ add_custom_target (
7+ picobench-run-example-${name}
8+ COMMAND ${tgt}
9+ )
10+ endmacro ()
11+
12+ pb_example(basic basic.cpp)
Original file line number Diff line number Diff line change 1+ #define PICOBENCH_DEBUG
2+ #define PICOBENCH_IMPLEMENT_WITH_MAIN
3+ #include " codspeed_picobench_compat/picobench.hpp"
4+
5+ #include < vector>
6+ #include < deque>
7+ #include < cstdlib>
8+
9+ void rand_vector (picobench::state& s)
10+ {
11+ std::vector<int > v;
12+ for (auto _ : s)
13+ {
14+ v.push_back (rand ());
15+ }
16+ }
17+ PICOBENCH (rand_vector);
18+
19+ void rand_vector_reserve (picobench::state& s)
20+ {
21+ std::vector<int > v;
22+ v.reserve (s.iterations ());
23+ for (auto _ : s)
24+ {
25+ v.push_back (rand ());
26+ }
27+ }
28+ PICOBENCH (rand_vector_reserve);
29+
30+ void rand_deque (picobench::state& s)
31+ {
32+ std::deque<int > v;
33+ for (auto _ : s)
34+ {
35+ v.push_back (rand ());
36+ }
37+ }
38+ PICOBENCH (rand_deque);
Original file line number Diff line number Diff line change 1+ #ifndef CODSPEED_PICOBENCH_COMPAT_HPP_INCLUDED
2+ #define CODSPEED_PICOBENCH_COMPAT_HPP_INCLUDED
3+
4+ #include " picobench/picobench.hpp"
5+ #include < iostream>
6+
7+ // Undefine the original PICOBENCH macro
8+ // #undef PICOBENCH
9+
10+ // Define a new PICOBENCH macro that wraps the original functionality
11+ #define PICOBENCH2 (func ) \
12+ do { \
13+ std::cout << " Registering benchmark for " << #func << std::endl; \
14+ static auto & I_PICOBENCH_PP_CAT (picobench, PICOBENCH_UNIQUE_SYM_SUFFIX) = \
15+ PICOBENCH_NAMESPACE::global_registry::new_benchmark (#func, func); \
16+ } while (0 )
17+
18+ #endif // CODSPEED_PICOBENCH_COMPAT_HPP_INCLUDED
You can’t perform that action at this time.
0 commit comments