Skip to content

Commit 782fec7

Browse files
committed
update pushback_benchmark
1 parent 6a3337e commit 782fec7

File tree

2 files changed

+52
-18
lines changed

2 files changed

+52
-18
lines changed

benchmarks/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ target_link_libraries(
1717
beman.inplace_vector.benchmark.push_back
1818
PRIVATE beman.inplace_vector benchmark::benchmark
1919
)
20+
21+
add_executable(beman.inplace_vector.benchmark.access access_benchmark.cpp)
22+
target_link_libraries(
23+
beman.inplace_vector.benchmark.access
24+
PRIVATE beman.inplace_vector benchmark::benchmark
25+
)

benchmarks/pushback_benchmark.cpp

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,70 @@
11
#include "beman/inplace_vector/inplace_vector.hpp"
2+
23
#include <benchmark/benchmark.h>
34
#include <cstddef>
5+
#include <iostream>
46
#include <vector>
57

68
using beman::inplace_vector;
79

8-
template <std::size_t Capacity>
9-
void InplaceVectorPushback(benchmark::State &state) {
10-
for (auto _ : state) {
11-
using IV = inplace_vector<int, Capacity>;
10+
template <std::size_t Capacity> void InplaceVector(benchmark::State &state) {
11+
using IV = inplace_vector<int, Capacity>;
12+
IV v;
13+
v.reserve(Capacity);
1214

13-
IV v;
15+
while (state.KeepRunningBatch(Capacity)) {
16+
// while (state.KeepRunning()) {
17+
v.clear();
1418
for (typename IV::size_type i = 0; i < Capacity; ++i)
1519
v.push_back(i);
1620
benchmark::DoNotOptimize(v);
1721
}
1822
}
1923

20-
template <std::size_t Capacity> void VetorPushback(benchmark::State &state) {
21-
for (auto _ : state) {
22-
using IV = std::vector<int>;
24+
template <std::size_t Capacity> void StdVector(benchmark::State &state) {
25+
using IV = std::vector<int>;
26+
IV v;
27+
v.reserve(Capacity);
2328

24-
IV v;
25-
v.reserve(Capacity);
29+
while (state.KeepRunningBatch(Capacity)) {
30+
// while (state.KeepRunning()) {
31+
v.clear();
2632
for (typename IV::size_type i = 0; i < Capacity; ++i)
2733
v.push_back(i);
2834
benchmark::DoNotOptimize(v);
2935
}
3036
}
3137

32-
BENCHMARK_TEMPLATE(InplaceVectorPushback, 128);
33-
BENCHMARK_TEMPLATE(InplaceVectorPushback, 256);
34-
BENCHMARK_TEMPLATE(InplaceVectorPushback, 512);
35-
BENCHMARK_TEMPLATE(InplaceVectorPushback, 1024);
38+
template <typename V, bool use_reserve> struct Meta {
39+
using Vector = V;
40+
constexpr static bool Reserve = use_reserve;
41+
};
42+
43+
#define BENCHMARK_VEC_L1(ARG) \
44+
BENCHMARK_TEMPLATE(ARG, 3); \
45+
BENCHMARK_TEMPLATE(ARG, 7); \
46+
BENCHMARK_TEMPLATE(ARG, 15); \
47+
BENCHMARK_TEMPLATE(ARG, 31); \
48+
BENCHMARK_TEMPLATE(ARG, 63); \
49+
BENCHMARK_TEMPLATE(ARG, 127); \
50+
BENCHMARK_TEMPLATE(ARG, 255); \
51+
BENCHMARK_TEMPLATE(ARG, 511); \
52+
BENCHMARK_TEMPLATE(ARG, 1023);
53+
54+
#define BENCHMARK_VEC_L2_L3(ARG) \
55+
BENCHMARK_TEMPLATE(ARG, 1 << 10); \
56+
BENCHMARK_TEMPLATE(ARG, 1 << 11); \
57+
BENCHMARK_TEMPLATE(ARG, 1 << 12); \
58+
BENCHMARK_TEMPLATE(ARG, 1 << 14); \
59+
BENCHMARK_TEMPLATE(ARG, 1 << 15); \
60+
BENCHMARK_TEMPLATE(ARG, 1 << 16); \
61+
BENCHMARK_TEMPLATE(ARG, 1 << 17); \
62+
BENCHMARK_TEMPLATE(ARG, 1 << 18);
63+
64+
BENCHMARK_VEC_L1(InplaceVector);
65+
BENCHMARK_VEC_L1(StdVector);
3666

37-
BENCHMARK_TEMPLATE(VetorPushback, 128);
38-
BENCHMARK_TEMPLATE(VetorPushback, 256);
39-
BENCHMARK_TEMPLATE(VetorPushback, 512);
40-
BENCHMARK_TEMPLATE(VetorPushback, 1024);
67+
BENCHMARK_VEC_L2_L3(InplaceVector);
68+
BENCHMARK_VEC_L2_L3(StdVector);
4169

4270
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)