1 | #include <cstdint> |
2 | #include <cstdlib> |
3 | #include <cstring> |
4 | #include <deque> |
5 | #include <functional> |
6 | #include <vector> |
7 | |
8 | #include "benchmark/benchmark.h" |
9 | |
10 | #include "ContainerBenchmarks.h" |
11 | #include "GenerateInput.h" |
12 | |
13 | using namespace ContainerBenchmarks; |
14 | |
15 | constexpr std::size_t TestNumInputs = 1024; |
16 | |
17 | BENCHMARK_CAPTURE(BM_ConstructSize, vector_byte, std::vector<unsigned char>{})->Arg(5140480); |
18 | |
19 | BENCHMARK_CAPTURE(BM_CopyConstruct, vector_int, std::vector<int>{})->Arg(5140480); |
20 | |
21 | BENCHMARK_CAPTURE(BM_Assignment, vector_int, std::vector<int>{})->Arg(5140480); |
22 | |
23 | BENCHMARK_CAPTURE(BM_ConstructSizeValue, vector_byte, std::vector<unsigned char>{}, 0)->Arg(5140480); |
24 | |
25 | BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_char, std::vector<char>{}, getRandomIntegerInputs<char>) |
26 | ->Arg(TestNumInputs); |
27 | |
28 | BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_size_t, std::vector<size_t>{}, getRandomIntegerInputs<size_t>) |
29 | ->Arg(TestNumInputs); |
30 | |
31 | BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_string, std::vector<std::string>{}, getRandomStringInputs) |
32 | ->Arg(TestNumInputs); |
33 | |
34 | BENCHMARK_CAPTURE(BM_ConstructFromRange, vector_char, std::vector<char>{}, getRandomIntegerInputs<char>) |
35 | ->Arg(TestNumInputs); |
36 | |
37 | BENCHMARK_CAPTURE(BM_ConstructFromRange, vector_size_t, std::vector<size_t>{}, getRandomIntegerInputs<size_t>) |
38 | ->Arg(TestNumInputs); |
39 | |
40 | BENCHMARK_CAPTURE(BM_ConstructFromRange, vector_string, std::vector<std::string>{}, getRandomStringInputs) |
41 | ->Arg(TestNumInputs); |
42 | |
43 | BENCHMARK_CAPTURE(BM_Pushback_no_grow, vector_int, std::vector<int>{})->Arg(TestNumInputs); |
44 | |
45 | template <class T> |
46 | void bm_grow(benchmark::State& state) { |
47 | for (auto _ : state) { |
48 | std::vector<T> vec; |
49 | benchmark::DoNotOptimize(vec); |
50 | for (size_t i = 0; i != 2048; ++i) |
51 | vec.emplace_back(); |
52 | benchmark::DoNotOptimize(vec); |
53 | } |
54 | } |
55 | BENCHMARK(bm_grow<int>); |
56 | BENCHMARK(bm_grow<std::string>); |
57 | BENCHMARK(bm_grow<std::unique_ptr<int>>); |
58 | BENCHMARK(bm_grow<std::deque<int>>); |
59 | |
60 | BENCHMARK_MAIN(); |
61 | |