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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03
10
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(res: 128);
21 iss.str(s: "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(value&: iss);
25
26 std::getline(is&: iss, str&: str);
27 benchmark::DoNotOptimize(value&: str);
28 iss.seekg(0);
29 }
30}
31
32BENCHMARK(BM_getline_string);
33
34BENCHMARK_MAIN();
35

source code of libcxx/test/benchmarks/streams/getline.bench.cpp