35 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++0310 11#include <istream>12#include <sstream>13 14#include <benchmark/benchmark.h>15 16void BM_getline_string(benchmark::State& state) {17 std::istringstream iss;18 19 std::string str;20 str.reserve(128);21 iss.str("A long string to let getline do some more work, making sure that longer strings are parsed fast enough");22 23 for (auto _ : state) {24 benchmark::DoNotOptimize(iss);25 26 std::getline(iss, str);27 benchmark::DoNotOptimize(str);28 iss.seekg(0);29 }30}31 32BENCHMARK(BM_getline_string);33 34BENCHMARK_MAIN();35