[libcxx-commits] [libcxx] [libc++] Optimize ctype::to{lower, upper} (PR #145344)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 25 08:13:06 PDT 2025


================
@@ -0,0 +1,69 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14
+
+#include <locale>
+
+#include <benchmark/benchmark.h>
+
+#include "make_string.h"
+
+template <class CharT>
+static void BM_tolower_char(benchmark::State& state) {
+  const auto& ct = std::use_facet<std::ctype<CharT>>(std::locale::classic());
+
+  for (auto _ : state) {
+    benchmark::DoNotOptimize(ct.tolower(CharT('c')));
----------------
ldionne wrote:

Minor nit: let's make it so that the compiler can't optimize based on the known value of `CharT('c')`. That way the benchmark will make sense even if the implementation of `tolower` were in the headers.

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


More information about the libcxx-commits mailing list