[libcxx-commits] [libcxx] [libc++] Rewrite std::regex (PR #217680)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 21 08:59:37 PDT 2026


================
@@ -0,0 +1,96 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+#include <regex>
+
+#include "benchmark/benchmark.h"
+#include "GenerateInput.h"
+
+template <std::regex_constants::syntax_option_type Arg>
+static void BM_regex_construct(benchmark::State& state) {
+  static std::string_view regexes[] = {".*[abcdefghijklmnopqrtuvwxyz]{10,100}", "This is technically a regex."};
+  while (state.KeepRunningBatch(std::size(regexes))) {
+    for (auto& reg : regexes)
+      std::regex r(reg.data(), Arg);
+  }
+}
+BENCHMARK(BM_regex_construct<std::regex::basic>);
+BENCHMARK(BM_regex_construct<std::regex::extended>);
+BENCHMARK(BM_regex_construct<std::regex::awk>);
+BENCHMARK(BM_regex_construct<std::regex::ECMAScript>);
+
+static void BM_regex_run_bad_match(benchmark::State& state) {
+  std::regex r("This is technically a regex.");
+  std::string input = getRandomString(1 << 16);
+
+  for (auto _ : state) {
+    std::regex_search(input, r);
+  }
+}
+BENCHMARK(BM_regex_run_bad_match);
----------------
ldionne wrote:

Since these benchmarks are measuring `std::regex_search`, their name should reflect that, to stay consistent with our other benchmarks.

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


More information about the libcxx-commits mailing list