@@ -32,6 +32,7 @@ static bool exception_ptr_moves_copies_swap(std::exception_ptr p1) {
3232 return is_null && is_equal;
3333}
3434
35+ // Benchmark copies, moves and comparisons of a non-null exception_ptr.
3536void bm_nonnull_exception_ptr (benchmark::State& state) {
3637 std::exception_ptr excptr = std::make_exception_ptr (42 );
3738 for (auto _ : state) {
@@ -41,23 +42,22 @@ void bm_nonnull_exception_ptr(benchmark::State& state) {
4142}
4243BENCHMARK (bm_nonnull_exception_ptr);
4344
45+ // Benchmark copies, moves and comparisons of a nullptr exception_ptr
46+ // where the compiler cannot prove that the exception_ptr is always
47+ // a nullptr and needs to emit runtime checks.
4448void bm_null_exception_ptr (benchmark::State& state) {
4549 std::exception_ptr excptr;
4650 for (auto _ : state) {
47- // All of the `exception_ptr_noops` are no-ops but the optimizer
48- // cannot optimize them away, because the `DoNotOptimize` calls
49- // prevent the optimizer from doing so.
5051 benchmark::DoNotOptimize (excptr);
5152 benchmark::DoNotOptimize (exception_ptr_moves_copies_swap (excptr));
5253 }
5354}
5455BENCHMARK (bm_null_exception_ptr);
5556
57+ // Benchmark copies, moves and comparisons of a nullptr exception_ptr
58+ // where the compiler can proof that the exception_ptr is always a nullptr.
5659void bm_optimized_null_exception_ptr (benchmark::State& state) {
5760 for (auto _ : state) {
58- // All of the `exception_ptr_noops` are no-ops because
59- // the exception_ptr is empty. Hence, the compiler should
60- // be able to optimize them very aggressively.
6161 benchmark::DoNotOptimize (exception_ptr_moves_copies_swap (std::exception_ptr{nullptr }));
6262 }
6363}
0 commit comments