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 <ios> |
12 | #include <locale> |
13 | |
14 | #include <benchmark/benchmark.h> |
15 | |
16 | struct num_put : std::num_put<char, std::string::iterator> {}; |
17 | |
18 | template <class T> |
19 | void BM_num_put(benchmark::State& state) { |
20 | auto val = T(123); |
21 | std::ios ios(nullptr); |
22 | num_put np; |
23 | |
24 | for (auto _ : state) { |
25 | benchmark::DoNotOptimize(val); |
26 | std::string str; |
27 | benchmark::DoNotOptimize(np.put(str.begin(), ios, ' ', val)); |
28 | } |
29 | } |
30 | BENCHMARK(BM_num_put<bool>); |
31 | BENCHMARK(BM_num_put<long>); |
32 | BENCHMARK(BM_num_put<long long>); |
33 | BENCHMARK(BM_num_put<unsigned long>); |
34 | BENCHMARK(BM_num_put<unsigned long long>); |
35 | BENCHMARK(BM_num_put<double>); |
36 | BENCHMARK(BM_num_put<long double>); |
37 | BENCHMARK(BM_num_put<const void*>); |
38 | |
39 | BENCHMARK_MAIN(); |
40 |