//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 #include #include #include #include #include #include #include #include #include "benchmark/benchmark.h" #include "ContainerBenchmarks.h" #include "../GenerateInput.h" using namespace ContainerBenchmarks; constexpr std::size_t TestNumInputs = 1024; BENCHMARK_CAPTURE(BM_ConstructSize, vector_byte, std::vector{})->Arg(5140480); BENCHMARK_CAPTURE(BM_CopyConstruct, vector_int, std::vector{})->Arg(5140480); BENCHMARK_CAPTURE(BM_Assignment, vector_int, std::vector{})->Arg(5140480); BENCHMARK_CAPTURE(BM_ConstructSizeValue, vector_byte, std::vector{}, 0)->Arg(5140480); BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_char, std::vector{}, getRandomIntegerInputs) ->Arg(TestNumInputs); BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_size_t, std::vector{}, getRandomIntegerInputs) ->Arg(TestNumInputs); BENCHMARK_CAPTURE(BM_ConstructIterIter, vector_string, std::vector{}, getRandomStringInputs) ->Arg(TestNumInputs); BENCHMARK_CAPTURE(BM_ConstructFromRange, vector_char, std::vector{}, getRandomIntegerInputs) ->Arg(TestNumInputs); BENCHMARK_CAPTURE(BM_ConstructFromRange, vector_size_t, std::vector{}, getRandomIntegerInputs) ->Arg(TestNumInputs); BENCHMARK_CAPTURE(BM_ConstructFromRange, vector_string, std::vector{}, getRandomStringInputs) ->Arg(TestNumInputs); BENCHMARK_CAPTURE(BM_Pushback_no_grow, vector_int, std::vector{})->Arg(TestNumInputs); BENCHMARK_CAPTURE(BM_erase_iter_in_middle, vector_int, std::vector{}, getRandomIntegerInputs) ->Range(TestNumInputs, TestNumInputs * 10); BENCHMARK_CAPTURE(BM_erase_iter_in_middle, vector_string, std::vector{}, getRandomStringInputs) ->Range(TestNumInputs, TestNumInputs * 10); BENCHMARK_CAPTURE(BM_erase_iter_at_start, vector_int, std::vector{}, getRandomIntegerInputs) ->Range(TestNumInputs, TestNumInputs * 10); BENCHMARK_CAPTURE(BM_erase_iter_at_start, vector_string, std::vector{}, getRandomStringInputs) ->Range(TestNumInputs, TestNumInputs * 10); template void bm_grow(benchmark::State& state) { for (auto _ : state) { std::vector vec; benchmark::DoNotOptimize(vec); for (size_t i = 0; i != 2048; ++i) vec.emplace_back(); benchmark::DoNotOptimize(vec); } } BENCHMARK(bm_grow); BENCHMARK(bm_grow); BENCHMARK(bm_grow>); BENCHMARK(bm_grow>); BENCHMARK_CAPTURE(BM_AssignInputIterIter, vector_int, std::vector{}, getRandomIntegerInputs) ->Args({TestNumInputs, TestNumInputs}); BENCHMARK_CAPTURE( BM_AssignInputIterIter<32>, vector_string, std::vector{}, getRandomStringInputsWithLength) ->Args({TestNumInputs, TestNumInputs}); BENCHMARK_CAPTURE(BM_AssignInputIterIter<100>, vector_vector_int, std::vector>{}, getRandomIntegerInputsWithLength) ->Args({TestNumInputs, TestNumInputs}); BENCHMARK_MAIN();