[libcxx-commits] [libcxx] [libc++] Refactor variant benchmarks (PR #174743)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jan 7 02:59:12 PST 2026


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/174743

The variant benchmarks are incredibly slow to compile and run currently. This is due to them being incredibly exhaustive. This is usually a good thing, but the exhaustiveness makes it almost prohibitive to actually run the benchmarks. Even the new, incredibly reduced, set still requires almost 40 seconds to just compile on my system.


>From 4f4d7818a8fa29f3854e050bed65033d0106ceee Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Wed, 7 Jan 2026 11:55:24 +0100
Subject: [PATCH] [libc++] Refactor variant benchmarks

---
 ...{VariantBenchmarks.h => variant.bench.cpp} | 24 ++++++------
 .../test/benchmarks/variant_visit_1.bench.cpp | 37 -------------------
 .../test/benchmarks/variant_visit_2.bench.cpp | 32 ----------------
 .../test/benchmarks/variant_visit_3.bench.cpp | 30 ---------------
 4 files changed, 12 insertions(+), 111 deletions(-)
 rename libcxx/test/benchmarks/{VariantBenchmarks.h => variant.bench.cpp} (80%)
 delete mode 100644 libcxx/test/benchmarks/variant_visit_1.bench.cpp
 delete mode 100644 libcxx/test/benchmarks/variant_visit_2.bench.cpp
 delete mode 100644 libcxx/test/benchmarks/variant_visit_3.bench.cpp

diff --git a/libcxx/test/benchmarks/VariantBenchmarks.h b/libcxx/test/benchmarks/variant.bench.cpp
similarity index 80%
rename from libcxx/test/benchmarks/VariantBenchmarks.h
rename to libcxx/test/benchmarks/variant.bench.cpp
index bb0c714279150..08fd530b0a335 100644
--- a/libcxx/test/benchmarks/VariantBenchmarks.h
+++ b/libcxx/test/benchmarks/variant.bench.cpp
@@ -1,4 +1,3 @@
-// -*- C++ -*-
 //===----------------------------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
@@ -7,21 +6,14 @@
 //
 //===----------------------------------------------------------------------===//
 
-#ifndef BENCHMARK_VARIANT_BENCHMARKS_H
-#define BENCHMARK_VARIANT_BENCHMARKS_H
+// UNSUPPORTED: c++03, c++11, c++14, c++17
 
 #include <array>
-#include <cstddef>
-#include <tuple>
-#include <type_traits>
 #include <variant>
 
 #include "benchmark/benchmark.h"
-
 #include "GenerateInput.h"
 
-namespace VariantBenchmarks {
-
 template <std::size_t I>
 struct S {
   static constexpr size_t v = I;
@@ -50,6 +42,14 @@ static void BM_Visit(benchmark::State& state) {
   }
 }
 
-} // namespace VariantBenchmarks
-
-#endif // BENCHMARK_VARIANT_BENCHMARKS_H
+BENCHMARK(BM_Visit<1, 1>);
+BENCHMARK(BM_Visit<1, 8>);
+BENCHMARK(BM_Visit<1, 100>);
+BENCHMARK(BM_Visit<2, 1>);
+BENCHMARK(BM_Visit<2, 8>);
+BENCHMARK(BM_Visit<2, 50>);
+BENCHMARK(BM_Visit<3, 1>);
+BENCHMARK(BM_Visit<3, 8>);
+BENCHMARK(BM_Visit<3, 20>);
+
+BENCHMARK_MAIN();
diff --git a/libcxx/test/benchmarks/variant_visit_1.bench.cpp b/libcxx/test/benchmarks/variant_visit_1.bench.cpp
deleted file mode 100644
index f1b702530bed3..0000000000000
--- a/libcxx/test/benchmarks/variant_visit_1.bench.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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, c++17
-
-#include "benchmark/benchmark.h"
-
-#include "VariantBenchmarks.h"
-
-using namespace VariantBenchmarks;
-
-BENCHMARK(BM_Visit<1, 1>);
-BENCHMARK(BM_Visit<1, 2>);
-BENCHMARK(BM_Visit<1, 3>);
-BENCHMARK(BM_Visit<1, 4>);
-BENCHMARK(BM_Visit<1, 5>);
-BENCHMARK(BM_Visit<1, 6>);
-BENCHMARK(BM_Visit<1, 7>);
-BENCHMARK(BM_Visit<1, 8>);
-BENCHMARK(BM_Visit<1, 9>);
-BENCHMARK(BM_Visit<1, 10>);
-BENCHMARK(BM_Visit<1, 20>);
-BENCHMARK(BM_Visit<1, 30>);
-BENCHMARK(BM_Visit<1, 40>);
-BENCHMARK(BM_Visit<1, 50>);
-BENCHMARK(BM_Visit<1, 60>);
-BENCHMARK(BM_Visit<1, 70>);
-BENCHMARK(BM_Visit<1, 80>);
-BENCHMARK(BM_Visit<1, 90>);
-BENCHMARK(BM_Visit<1, 100>);
-
-BENCHMARK_MAIN();
diff --git a/libcxx/test/benchmarks/variant_visit_2.bench.cpp b/libcxx/test/benchmarks/variant_visit_2.bench.cpp
deleted file mode 100644
index 7dd8d02b358be..0000000000000
--- a/libcxx/test/benchmarks/variant_visit_2.bench.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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, c++17
-
-#include "benchmark/benchmark.h"
-
-#include "VariantBenchmarks.h"
-
-using namespace VariantBenchmarks;
-
-BENCHMARK(BM_Visit<2, 1>);
-BENCHMARK(BM_Visit<2, 2>);
-BENCHMARK(BM_Visit<2, 3>);
-BENCHMARK(BM_Visit<2, 4>);
-BENCHMARK(BM_Visit<2, 5>);
-BENCHMARK(BM_Visit<2, 6>);
-BENCHMARK(BM_Visit<2, 7>);
-BENCHMARK(BM_Visit<2, 8>);
-BENCHMARK(BM_Visit<2, 9>);
-BENCHMARK(BM_Visit<2, 10>);
-BENCHMARK(BM_Visit<2, 20>);
-BENCHMARK(BM_Visit<2, 30>);
-BENCHMARK(BM_Visit<2, 40>);
-BENCHMARK(BM_Visit<2, 50>);
-
-BENCHMARK_MAIN();
diff --git a/libcxx/test/benchmarks/variant_visit_3.bench.cpp b/libcxx/test/benchmarks/variant_visit_3.bench.cpp
deleted file mode 100644
index 0fe42b0d8e009..0000000000000
--- a/libcxx/test/benchmarks/variant_visit_3.bench.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// 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, c++17
-
-#include "benchmark/benchmark.h"
-
-#include "VariantBenchmarks.h"
-
-using namespace VariantBenchmarks;
-
-BENCHMARK(BM_Visit<3, 1>);
-BENCHMARK(BM_Visit<3, 2>);
-BENCHMARK(BM_Visit<3, 3>);
-BENCHMARK(BM_Visit<3, 4>);
-BENCHMARK(BM_Visit<3, 5>);
-BENCHMARK(BM_Visit<3, 6>);
-BENCHMARK(BM_Visit<3, 7>);
-BENCHMARK(BM_Visit<3, 8>);
-BENCHMARK(BM_Visit<3, 9>);
-BENCHMARK(BM_Visit<3, 10>);
-BENCHMARK(BM_Visit<3, 15>);
-BENCHMARK(BM_Visit<3, 20>);
-
-BENCHMARK_MAIN();



More information about the libcxx-commits mailing list