[libcxx-commits] [libcxx] [libc++] Add benchmarks for throw/catch (PR #231000)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Oct 11 08:52:10 PDT 2026
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/231000
None
>From a9925d1ee0eab163c40116fd99c6fa7c8f0f3d81 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Sun, 11 Oct 2026 17:51:47 +0200
Subject: [PATCH] [libc++] Add benchmarks for throw/catch
---
.../libcxxabi/dynamic_cast.bench.cpp | 45 +++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/libcxx/test/benchmarks/libcxxabi/dynamic_cast.bench.cpp b/libcxx/test/benchmarks/libcxxabi/dynamic_cast.bench.cpp
index 019d0c04ba3a8..7b5a878c49969 100644
--- a/libcxx/test/benchmarks/libcxxabi/dynamic_cast.bench.cpp
+++ b/libcxx/test/benchmarks/libcxxabi/dynamic_cast.bench.cpp
@@ -172,4 +172,49 @@ BENCHMARK(DynCast<VDag<0, 3>, VDag<3, 0>, void>)->Name("dynamic_cast (VDAG to co
// Static cast as the baseline.
BENCHMARK(StaticCast)->Name("static_cast");
+template <class ThrowT, class CatchT>
+static TEST_ALIGN_BENCHMARK void ThrowCatch(benchmark::State& state) {
+ for (auto _ : state) {
+ try {
+ throw ThrowT();
+ } catch (CatchT& v) {
+ benchmark::DoNotOptimize(v);
+ }
+ }
+}
+
+// Downcast along a chain from base to the most derived type
+BENCHMARK(ThrowCatch<Chain<1>, Chain<0>>)->Name("throw/catch (Chain, 1 level)");
+BENCHMARK(ThrowCatch<Chain<2>, Chain<0>>)->Name("throw/catch (Chain, 2 levels)");
+BENCHMARK(ThrowCatch<Chain<3>, Chain<0>>)->Name("throw/catch (Chain, 3 levels)");
+BENCHMARK(ThrowCatch<Chain<4>, Chain<0>>)->Name("throw/catch (Chain, 4 levels)");
+BENCHMARK(ThrowCatch<Chain<5>, Chain<0>>)->Name("throw/catch (Chain, 5 levels)");
+BENCHMARK(ThrowCatch<Chain<6>, Chain<0>>)->Name("throw/catch (Chain, 6 levels)");
+BENCHMARK(ThrowCatch<Chain<7>, Chain<0>>)->Name("throw/catch (Chain, 7 levels)");
+BENCHMARK(ThrowCatch<Chain<8>, Chain<0>>)->Name("throw/catch (Chain, 8 levels)");
+BENCHMARK(ThrowCatch<Chain<9>, Chain<0>>)->Name("throw/catch (Chain, 9 levels)");
+
+// Downcast along a virtual inheritance chain from base to the most derived type
+BENCHMARK(ThrowCatch<VChain<1>, VChain<0>>)->Name("throw/catch (VChain, 1 level)");
+BENCHMARK(ThrowCatch<VChain<2>, VChain<0>>)->Name("throw/catch (VChain, 2 levels)");
+BENCHMARK(ThrowCatch<VChain<3>, VChain<0>>)->Name("throw/catch (VChain, 3 levels)");
+BENCHMARK(ThrowCatch<VChain<4>, VChain<0>>)->Name("throw/catch (VChain, 4 levels)");
+BENCHMARK(ThrowCatch<VChain<5>, VChain<0>>)->Name("throw/catch (VChain, 5 levels)");
+
+// Downcast along a DAG from base to the most derived type
+BENCHMARK(ThrowCatch<Dag<0, 3>, Dag<3, 0>>)->Name("throw/catch (DAG rightmost, 3 levels)");
+BENCHMARK(ThrowCatch<Dag<0, 4>, Dag<4, 0>>)->Name("throw/catch (DAG rightmost, 4 levels)");
+BENCHMARK(ThrowCatch<Dag<0, 5>, Dag<5, 0>>)->Name("throw/catch (DAG rightmost, 5 levels)");
+BENCHMARK(ThrowCatch<Dag<0, 3>, Dag<0, 0>>)->Name("throw/catch (DAG leftmost, 3 levels)");
+BENCHMARK(ThrowCatch<Dag<0, 4>, Dag<0, 0>>)->Name("throw/catch (DAG leftmost, 4 levels)");
+BENCHMARK(ThrowCatch<Dag<0, 5>, Dag<0, 0>>)->Name("throw/catch (DAG leftmost, 5 levels)");
+
+// Downcast along a virtual inheritance DAG from base to the most derived type
+BENCHMARK(ThrowCatch<VDag<0, 3>, VDag<3, 0>>)->Name("throw/catch (VDAG rightmost, 3 levels)");
+BENCHMARK(ThrowCatch<VDag<0, 4>, VDag<4, 0>>)->Name("throw/catch (VDAG rightmost, 4 levels)");
+BENCHMARK(ThrowCatch<VDag<0, 5>, VDag<5, 0>>)->Name("throw/catch (VDAG rightmost, 5 levels)");
+BENCHMARK(ThrowCatch<VDag<0, 3>, VDag<0, 0>>)->Name("throw/catch (VDAG leftmost, 3 levels)");
+BENCHMARK(ThrowCatch<VDag<0, 4>, VDag<0, 0>>)->Name("throw/catch (VDAG leftmost, 4 levels)");
+BENCHMARK(ThrowCatch<VDag<0, 5>, VDag<0, 0>>)->Name("throw/catch (VDAG leftmost, 5 levels)");
+
BENCHMARK_MAIN();
More information about the libcxx-commits
mailing list