Skip to content

Commit c5492e3

Browse files
committed
[libc++] Add a benchmark for std::num_get
1 parent eaf67e0 commit c5492e3

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include <ios>
11+
#include <locale>
12+
13+
#include <benchmark/benchmark.h>
14+
15+
struct num_get : std::num_get<char, std::string::iterator> {};
16+
17+
template <class T>
18+
void BM_num_get(benchmark::State& state) {
19+
auto val = std::string("123");
20+
std::ios ios(nullptr);
21+
num_get np;
22+
23+
for (auto _ : state) {
24+
benchmark::DoNotOptimize(val);
25+
T out;
26+
std::ios_base::iostate err = ios.goodbit;
27+
benchmark::DoNotOptimize(np.get(val.begin(), val.end(), ios, err, out));
28+
benchmark::DoNotOptimize(out);
29+
}
30+
}
31+
32+
BENCHMARK(BM_num_get<bool>);
33+
BENCHMARK(BM_num_get<long>);
34+
BENCHMARK(BM_num_get<long long>);
35+
BENCHMARK(BM_num_get<unsigned short>);
36+
BENCHMARK(BM_num_get<unsigned int>);
37+
BENCHMARK(BM_num_get<unsigned long>);
38+
BENCHMARK(BM_num_get<unsigned long long>);
39+
BENCHMARK(BM_num_get<float>);
40+
BENCHMARK(BM_num_get<double>);
41+
BENCHMARK(BM_num_get<long double>);
42+
BENCHMARK(BM_num_get<void*>);
43+
44+
BENCHMARK_MAIN();

0 commit comments

Comments
 (0)