22 #include "benchmark/benchmark.h" 26 void BM_Join2_Strings(benchmark::State& state) {
27 const int string_len = state.range(0);
28 const int num_strings = state.range(1);
29 const std::string s(string_len,
'x');
30 const std::vector<std::string>
v(num_strings, s);
31 for (
auto _ : state) {
33 benchmark::DoNotOptimize(s);
36 BENCHMARK(BM_Join2_Strings)
37 ->ArgPair(1 << 0, 1 << 3)
38 ->ArgPair(1 << 10, 1 << 3)
39 ->ArgPair(1 << 13, 1 << 3)
40 ->ArgPair(1 << 0, 1 << 10)
41 ->ArgPair(1 << 10, 1 << 10)
42 ->ArgPair(1 << 13, 1 << 10)
43 ->ArgPair(1 << 0, 1 << 13)
44 ->ArgPair(1 << 10, 1 << 13)
45 ->ArgPair(1 << 13, 1 << 13);
47 void BM_Join2_Ints(benchmark::State& state) {
48 const int num_ints = state.range(0);
49 const std::vector<int>
v(num_ints, 42);
50 for (
auto _ : state) {
52 benchmark::DoNotOptimize(s);
55 BENCHMARK(BM_Join2_Ints)->Range(0, 1 << 13);
57 void BM_Join2_KeysAndValues(benchmark::State& state) {
58 const int string_len = state.range(0);
59 const int num_pairs = state.range(1);
60 const std::string s(string_len,
'x');
61 const std::vector<std::pair<std::string, int>>
v(num_pairs,
62 std::make_pair(s, 42));
63 for (
auto _ : state) {
65 benchmark::DoNotOptimize(s);
68 BENCHMARK(BM_Join2_KeysAndValues)
69 ->ArgPair(1 << 0, 1 << 3)
70 ->ArgPair(1 << 10, 1 << 3)
71 ->ArgPair(1 << 13, 1 << 3)
72 ->ArgPair(1 << 0, 1 << 10)
73 ->ArgPair(1 << 10, 1 << 10)
74 ->ArgPair(1 << 13, 1 << 10)
75 ->ArgPair(1 << 0, 1 << 13)
76 ->ArgPair(1 << 10, 1 << 13)
77 ->ArgPair(1 << 13, 1 << 13);
79 void BM_JoinStreamable(benchmark::State& state) {
80 const int string_len = state.range(0);
81 const int num_strings = state.range(1);
82 const std::vector<std::string>
v(num_strings, std::string(string_len,
'x'));
83 for (
auto _ : state) {
85 benchmark::DoNotOptimize(s);
88 BENCHMARK(BM_JoinStreamable)
std::string StrJoin(Iterator start, Iterator end, absl::string_view sep, Formatter &&fmt)
strings_internal::PairFormatterImpl< FirstFormatter, SecondFormatter > PairFormatter(FirstFormatter f1, absl::string_view sep, SecondFormatter f2)
strings_internal::StreamFormatterImpl StreamFormatter()