-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
``` ----------------------------------------------- Benchmark old new ----------------------------------------------- BM_getline_string 318 ns 32.4 ns ```
- Loading branch information
1 parent
8cb3d7b
commit 310f910
Showing
6 changed files
with
196 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03 | ||
|
||
#include <istream> | ||
#include <sstream> | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
void BM_getline_string(benchmark::State& state) { | ||
std::istringstream iss; | ||
|
||
std::string str; | ||
str.reserve(128); | ||
iss.str("A long string to let getline do some more work, making sure that longer strings are parsed fast enough"); | ||
|
||
for (auto _ : state) { | ||
benchmark::DoNotOptimize(iss); | ||
|
||
std::getline(iss, str); | ||
benchmark::DoNotOptimize(str); | ||
iss.seekg(0); | ||
} | ||
} | ||
|
||
BENCHMARK(BM_getline_string); | ||
|
||
BENCHMARK_MAIN(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef TEST_SUPPORT_STREAM_TYPE_H | ||
#define TEST_SUPPORT_STREAM_TYPE_H | ||
|
||
#include <streambuf> | ||
#include <string> | ||
#include <utility> | ||
|
||
template <class CharT> | ||
class non_buffering_streambuf : public std::basic_streambuf<CharT> { | ||
using char_type = CharT; | ||
using traits_type = std::char_traits<CharT>; | ||
using int_type = typename traits_type::int_type; | ||
|
||
public: | ||
non_buffering_streambuf(std::basic_string<char_type> underlying_data) | ||
: underlying_data_(std::move(underlying_data)), index_(0) {} | ||
|
||
protected: | ||
int_type underflow() override { | ||
if (index_ != underlying_data_.size()) | ||
return underlying_data_[index_]; | ||
return traits_type::eof(); | ||
} | ||
|
||
int_type uflow() override { | ||
if (index_ != underlying_data_.size()) | ||
return underlying_data_[index_++]; | ||
return traits_type::eof(); | ||
} | ||
|
||
private: | ||
std::basic_string<char_type> underlying_data_; | ||
size_t index_; | ||
}; | ||
|
||
#endif // TEST_SUPPORT_STREAM_TYPE_H |