[libcxx-commits] [libcxx] [libc++] Add benchmark for `std::exception_ptr` (PR #164278)

Adrian Vogelsgesang via libcxx-commits libcxx-commits at lists.llvm.org
Tue Oct 21 06:46:26 PDT 2025


================
@@ -18,4 +18,118 @@ void bm_make_exception_ptr(benchmark::State& state) {
 }
 BENCHMARK(bm_make_exception_ptr)->ThreadRange(1, 8);
 
+void bm_exception_ptr_copy_ctor_nonnull(benchmark::State& state) {
+  std::exception_ptr excptr = std::make_exception_ptr(42);
+  for (auto _ : state) {
+    benchmark::DoNotOptimize(std::exception_ptr(excptr));
+  }
+}
+BENCHMARK(bm_exception_ptr_copy_ctor_nonnull);
+
+void bm_exception_ptr_copy_ctor_null(benchmark::State& state) {
+  std::exception_ptr excptr = nullptr;
+  for (auto _ : state) {
+    std::exception_ptr excptr_copy(excptr);
+    benchmark::DoNotOptimize(excptr_copy);
+    // The compiler should be able to constant-fold the comparison
----------------
vogelsgesang wrote:

🤦 right... starring at those test cases for too long already today.
Swapping the two `DoNotOptimize` calls should fix it

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


More information about the libcxx-commits mailing list