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
13using namespace ContainerBenchmarks;
14
15constexpr std::size_t TestNumInputs = 1024;
16
17BENCHMARK_CAPTURE(BM_ConstructSize, vector_byte, std::vector<unsigned char>{})->Arg(5140480);
18
19BENCHMARK_CAPTURE(BM_CopyConstruct, vector_int, std::vector<int>{})->Arg(5140480);
20
21BENCHMARK_CAPTURE(BM_Assignment, vector_int, std::vector<int>{})->Arg(5140480);
22
23BENCHMARK_CAPTURE(BM_ConstructSizeValue, vector_byte, std::vector<unsigned char>{}, 0)->Arg(5140480);
24
25BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_char, std::vector<char>{}, getRandomIntegerInputs<char>)
26 ->Arg(TestNumInputs);
27
28BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_size_t, std::vector<size_t>{}, getRandomIntegerInputs<size_t>)
29 ->Arg(TestNumInputs);
30
31BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_string, std::vector<std::string>{}, getRandomStringInputs)
32 ->Arg(TestNumInputs);
33
34BENCHMARK_CAPTURE(BM_ConstructFromRange, vector_char, std::vector<char>{}, getRandomIntegerInputs<char>)
35 ->Arg(TestNumInputs);
36
37BENCHMARK_CAPTURE(BM_ConstructFromRange, vector_size_t, std::vector<size_t>{}, getRandomIntegerInputs<size_t>)
38 ->Arg(TestNumInputs);
39
40BENCHMARK_CAPTURE(BM_ConstructFromRange, vector_string, std::vector<std::string>{}, getRandomStringInputs)
41 ->Arg(TestNumInputs);
42
43BENCHMARK_CAPTURE(BM_Pushback_no_grow, vector_int, std::vector<int>{})->Arg(TestNumInputs);
44
45template <class T>
46void 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}
55BENCHMARK(bm_grow<int>);
56BENCHMARK(bm_grow<std::string>);
57BENCHMARK(bm_grow<std::unique_ptr<int>>);
58BENCHMARK(bm_grow<std::deque<int>>);
59
60BENCHMARK_MAIN();
61