[libcxx-commits] [libcxx] [libc++] Speed up classic locale (PR #70631)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Sun Nov 12 17:51:31 PST 2023


================
@@ -14,17 +15,72 @@ double istream_numbers() {
   double f1 = 0.0, f2 = 0.0, q = 0.0;
   for (int i = 0; i < 3; i++) {
     std::istringstream s(a[i]);
+    if (l)
+      s.imbue(*l);
     s >> a1 >> a2 >> a3 >> f1 >> a4 >> a5 >> f2 >> a6 >> a7;
     q += (a1 + a2 + a3 + a4 + a5 + a6 + a7 + f1 + f2) / 1000000;
   }
   return q;
 }
 
+struct LocaleSelector {
+  std::locale* imbue;
+  std::locale old;
+
+  LocaleSelector(benchmark::State& state) {
+    static std::mutex mu;
+    std::lock_guard l(mu);
+    switch (state.range(0)) {
+    case 0: {
----------------
ldionne wrote:

Is there any reason not to prefer having 4 different benchmarks instead?

https://github.com/llvm/llvm-project/pull/70631


More information about the libcxx-commits mailing list