[libcxx-commits] [libcxx] c5492e3 - [libc++] Add a benchmark for std::num_get
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Dec 22 11:44:27 PST 2024
Author: Nikolas Klauser
Date: 2024-12-22T20:44:16+01:00
New Revision: c5492e3c65e40cdcab9771b692f9ad437c65aa04
URL: https://github.com/llvm/llvm-project/commit/c5492e3c65e40cdcab9771b692f9ad437c65aa04
DIFF: https://github.com/llvm/llvm-project/commit/c5492e3c65e40cdcab9771b692f9ad437c65aa04.diff
LOG: [libc++] Add a benchmark for std::num_get
Added:
libcxx/test/benchmarks/locale/num_get.bench.cpp
Modified:
Removed:
################################################################################
diff --git a/libcxx/test/benchmarks/locale/num_get.bench.cpp b/libcxx/test/benchmarks/locale/num_get.bench.cpp
new file mode 100644
index 00000000000000..3588d120d00cba
--- /dev/null
+++ b/libcxx/test/benchmarks/locale/num_get.bench.cpp
@@ -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
+//
+//===----------------------------------------------------------------------===//
+
+#include <ios>
+#include <locale>
+
+#include <benchmark/benchmark.h>
+
+struct num_get : std::num_get<char, std::string::iterator> {};
+
+template <class T>
+void BM_num_get(benchmark::State& state) {
+ auto val = std::string("123");
+ std::ios ios(nullptr);
+ num_get np;
+
+ for (auto _ : state) {
+ benchmark::DoNotOptimize(val);
+ T out;
+ std::ios_base::iostate err = ios.goodbit;
+ benchmark::DoNotOptimize(np.get(val.begin(), val.end(), ios, err, out));
+ benchmark::DoNotOptimize(out);
+ }
+}
+
+BENCHMARK(BM_num_get<bool>);
+BENCHMARK(BM_num_get<long>);
+BENCHMARK(BM_num_get<long long>);
+BENCHMARK(BM_num_get<unsigned short>);
+BENCHMARK(BM_num_get<unsigned int>);
+BENCHMARK(BM_num_get<unsigned long>);
+BENCHMARK(BM_num_get<unsigned long long>);
+BENCHMARK(BM_num_get<float>);
+BENCHMARK(BM_num_get<double>);
+BENCHMARK(BM_num_get<long double>);
+BENCHMARK(BM_num_get<void*>);
+
+BENCHMARK_MAIN();
More information about the libcxx-commits
mailing list