File tree Expand file tree Collapse file tree 3 files changed +72
-0
lines changed
Expand file tree Collapse file tree 3 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,13 @@ option(
2727 ${PROJECT_IS_TOP_LEVEL}
2828)
2929
30+ # [CMAKE.SKIP_TESTS]
31+ option(
32+ BEMAN_INPLACE_VECTOR_BUILD_BENCHMARKS
33+ "Enable building benchmarks. Default : ON. Values: { ON, OFF }."
34+ ${PROJECT_IS_TOP_LEVEL}
35+ )
36+
3037include (GNUInstallDirs)
3138
3239add_library(beman.inplace_vector INTERFACE)
@@ -65,3 +72,7 @@ endif()
6572if(BEMAN_EXEMPLAR_BUILD_EXAMPLES)
6673 add_subdirectory(examples)
6774endif()
75+
76+ if(BEMAN_INPLACE_VECTOR_BUILD_BENCHMARKS)
77+ add_subdirectory(benchmarks)
78+ endif()
Original file line number Diff line number Diff line change 1+ include (FetchContent)
2+
3+ # Fetch Google benchmark
4+ FetchContent_Declare(
5+ benchmark
6+ GIT_REPOSITORY https://github.com/google/benchmark.git
7+ GIT_TAG
8+ c58e6d0710581e3a08d65c349664128a8d9a2461 # v1.9.1
9+ EXCLUDE_FROM_ALL
10+ )
11+
12+ set (BENCHMARK_ENABLE_GTEST_TESTS OFF )
13+ FetchContent_MakeAvailable(benchmark)
14+
15+ add_executable (beman.inplace_vector.benchmark.push_back pushback_benchmark.cpp)
16+ target_link_libraries (
17+ beman.inplace_vector.benchmark.push_back
18+ PRIVATE beman.inplace_vector benchmark::benchmark
19+ )
Original file line number Diff line number Diff line change 1+ #include " beman/inplace_vector/inplace_vector.hpp"
2+ #include < benchmark/benchmark.h>
3+ #include < cstddef>
4+ #include < vector>
5+
6+ using beman::inplace_vector;
7+
8+ template <std::size_t Capacity>
9+ void InplaceVectorPushback (benchmark::State &state) {
10+ for (auto _ : state) {
11+ using IV = inplace_vector<int , Capacity>;
12+
13+ IV v;
14+ for (typename IV::size_type i = 0 ; i < Capacity; ++i)
15+ v.push_back (i);
16+ benchmark::DoNotOptimize (v);
17+ }
18+ }
19+
20+ template <std::size_t Capacity> void VetorPushback (benchmark::State &state) {
21+ for (auto _ : state) {
22+ using IV = std::vector<int >;
23+
24+ IV v;
25+ v.reserve (Capacity);
26+ for (typename IV::size_type i = 0 ; i < Capacity; ++i)
27+ v.push_back (i);
28+ benchmark::DoNotOptimize (v);
29+ }
30+ }
31+
32+ BENCHMARK_TEMPLATE (InplaceVectorPushback, 128 );
33+ BENCHMARK_TEMPLATE (InplaceVectorPushback, 256 );
34+ BENCHMARK_TEMPLATE (InplaceVectorPushback, 512 );
35+ BENCHMARK_TEMPLATE (InplaceVectorPushback, 1024 );
36+
37+ BENCHMARK_TEMPLATE (VetorPushback, 128 );
38+ BENCHMARK_TEMPLATE (VetorPushback, 256 );
39+ BENCHMARK_TEMPLATE (VetorPushback, 512 );
40+ BENCHMARK_TEMPLATE (VetorPushback, 1024 );
41+
42+ BENCHMARK_MAIN ();
You can’t perform that action at this time.
0 commit comments