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 | // UNSUPPORTED: c++03 |
11 | |
12 | #include <ios> |
13 | #include <locale> |
14 | |
15 | #include <benchmark/benchmark.h> |
16 | |
17 | struct num_get : std::num_get<char, std::string::iterator> {}; |
18 | |
19 | template <class T> |
20 | void BM_num_get(benchmark::State& state) { |
21 | auto val = std::string("123"); |
22 | std::ios ios(nullptr); |
23 | num_get np; |
24 | |
25 | for (auto _ : state) { |
26 | benchmark::DoNotOptimize(value&: val); |
27 | T out; |
28 | std::ios_base::iostate err = ios.goodbit; |
29 | benchmark::DoNotOptimize(np.get(val.begin(), val.end(), ios, err, out)); |
30 | benchmark::DoNotOptimize(out); |
31 | } |
32 | } |
33 | |
34 | BENCHMARK(BM_num_get<bool>); |
35 | BENCHMARK(BM_num_get<long>); |
36 | BENCHMARK(BM_num_get<long long>); |
37 | BENCHMARK(BM_num_get<unsigned short>); |
38 | BENCHMARK(BM_num_get<unsigned int>); |
39 | BENCHMARK(BM_num_get<unsigned long>); |
40 | BENCHMARK(BM_num_get<unsigned long long>); |
41 | BENCHMARK(BM_num_get<float>); |
42 | BENCHMARK(BM_num_get<double>); |
43 | BENCHMARK(BM_num_get<long double>); |
44 | BENCHMARK(BM_num_get<void*>); |
45 | |
46 | BENCHMARK_MAIN(); |
47 |