[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:05 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')));
+ }
+}
+
+BENCHMARK(BM_tolower_char<char>);
+BENCHMARK(BM_tolower_char<wchar_t>);
+
+template <class CharT>
+static void BM_tolower_string(benchmark::State& state) {
+ const auto& ct = std::use_facet<std::ctype<CharT>>(std::locale::classic());
+ std::basic_string<CharT> str;
+
+ for (auto _ : state) {
+ str = MAKE_STRING_VIEW(CharT, "THIS IS A LONG STRING TO MAKE TO LOWER");
----------------
ldionne wrote:
Same comment here and below.
https://github.com/llvm/llvm-project/pull/145344
More information about the libcxx-commits
mailing list