20 #include "benchmark/benchmark.h" 30 template <StringType kOutput>
31 void BM_StdStream(benchmark::State& state) {
32 const int num_writes = state.range(0);
33 const int bytes_per_write = state.range(1);
34 const std::string payload(bytes_per_write,
'x');
35 for (
auto _ : state) {
36 std::ostringstream strm;
37 benchmark::DoNotOptimize(strm);
38 for (
int i = 0;
i != num_writes; ++
i) {
46 std::string s = strm.str();
47 benchmark::DoNotOptimize(s);
55 BENCHMARK_TEMPLATE(BM_StdStream, kNone)
61 BENCHMARK_TEMPLATE(BM_StdStream, kStdString)
67 template <StringType kOutput>
68 void BM_CustomStream(benchmark::State& state) {
69 const int num_writes = state.range(0);
70 const int bytes_per_write = state.range(1);
71 const std::string payload(bytes_per_write,
'x');
72 for (
auto _ : state) {
75 benchmark::DoNotOptimize(strm);
76 for (
int i = 0;
i != num_writes; ++
i) {
85 benchmark::DoNotOptimize(s);
93 BENCHMARK_TEMPLATE(BM_CustomStream, kNone)
101 BENCHMARK_TEMPLATE(BM_CustomStream, kStdString)
104 ->ArgPair(1024, 256);