message: bench: Add benchmark for parse_string()
diff: @@ -13,17 +13,30 @@ fizzy::bytes leb128u_encode(uint64_t value);
  namespace
  {
  +std::mt19937_64 g_gen{std::random_device{}()};
  +
  template <typename T>
  std::vector<T> generate_samples(size_t count)
  {
  - std::mt19937_64 gen{std::random_device{}()};
  std::uniform_int_distribution<T> dist;
  std::vector<T> samples;
  samples.reserve(count);
  - std::generate_n(std::back_inserter(samples), count, [&] { return dist(gen); });
  + std::generate_n(std::back_inserter(samples), count, [&] { return dist(g_gen); });
  return samples;
  }
  +
  +fizzy::bytes generate_ascii_vec(size_t size)
  +{
  + std::uniform_int_distribution<uint8_t> dist{0, 0x7f};
  +
  + const auto size_encoded = leb128u_encode(size);
  + fizzy::bytes result;
  + result.reserve(size + size_encoded.size());
  + result += size_encoded;
  + std::generate_n(std::back_inserter(result), size, [&] { return dist(g_gen); });
  + return result;
  +}
  } // namespace
  template <decltype(fizzy::leb128u_decode<uint64_t>) Fn>
  @@ -57,3 +70,21 @@ BENCHMARK_TEMPLATE(leb128u_decode_u64, nop);
  BENCHMARK_TEMPLATE(leb128u_decode_u64, fizzy::leb128u_decode<uint64_t>);
  BENCHMARK_TEMPLATE(leb128u_decode_u64, leb128u_decode_u64_noinline);
  BENCHMARK_TEMPLATE(leb128u_decode_u64, decodeULEB128);
  +
  +static void parse_string(benchmark::State& state)
  +{
  + const auto size = static_cast<size_t>(state.range(0));
  + const auto input = generate_ascii_vec(size);
  + const auto input_begin = input.data();
  + const auto input_end = input_begin + input.size();
  + benchmark::ClobberMemory();
  +
  + for (auto _ : state)
  + {
  + (void)_;
  + fizzy::parse_string(input_begin, input_end);
  + }
  +
  + state.SetItemsProcessed(static_cast<int64_t>(size));
  +}
  +BENCHMARK(parse_string)->RangeMultiplier(2)->Range(16, 4 * 1024);
  