@@ -18,7 +18,116 @@ void bm_make_exception_ptr(benchmark::State& state) {
1818}
1919BENCHMARK (bm_make_exception_ptr)->ThreadRange(1 , 8 );
2020
21- static bool exception_ptr_moves_copies_swap (std::exception_ptr p1) {
21+ void bm_exception_ptr_copy_ctor_nonnull (benchmark::State& state) {
22+ std::exception_ptr excptr = std::make_exception_ptr (42 );
23+ for (auto _ : state) {
24+ benchmark::DoNotOptimize (excptr);
25+ benchmark::DoNotOptimize (std::exception_ptr (excptr));
26+ }
27+ }
28+ BENCHMARK (bm_exception_ptr_copy_ctor_nonnull);
29+
30+ void bm_exception_ptr_copy_ctor_null (benchmark::State& state) {
31+ std::exception_ptr excptr = nullptr ;
32+ for (auto _ : state) {
33+ benchmark::DoNotOptimize (excptr);
34+ benchmark::DoNotOptimize (std::exception_ptr (excptr));
35+ }
36+ }
37+ BENCHMARK (bm_exception_ptr_copy_ctor_null);
38+
39+
40+ void bm_exception_ptr_move_ctor_nonnull (benchmark::State& state) {
41+ std::exception_ptr excptr = std::make_exception_ptr (42 );
42+ for (auto _ : state) {
43+ benchmark::DoNotOptimize (excptr);
44+ benchmark::DoNotOptimize (std::exception_ptr (std::move (excptr)));
45+ }
46+ }
47+ BENCHMARK (bm_exception_ptr_move_ctor_nonnull);
48+
49+ void bm_exception_ptr_move_ctor_null (benchmark::State& state) {
50+ std::exception_ptr excptr = nullptr ;
51+ for (auto _ : state) {
52+ benchmark::DoNotOptimize (excptr);
53+ benchmark::DoNotOptimize (std::exception_ptr (std::move (excptr)));
54+ }
55+ }
56+ BENCHMARK (bm_exception_ptr_move_ctor_null);
57+
58+ void bm_exception_ptr_copy_assign_nonnull (benchmark::State& state) {
59+ std::exception_ptr excptr = std::make_exception_ptr (42 );
60+ for (auto _ : state) {
61+ benchmark::DoNotOptimize (excptr);
62+ std::exception_ptr new_excptr;
63+ new_excptr = excptr;
64+ benchmark::DoNotOptimize (new_excptr);
65+ }
66+ }
67+ BENCHMARK (bm_exception_ptr_copy_assign_nonnull);
68+
69+ void bm_exception_ptr_copy_assign_null (benchmark::State& state) {
70+ std::exception_ptr excptr = nullptr ;
71+ for (auto _ : state) {
72+ benchmark::DoNotOptimize (excptr);
73+ std::exception_ptr new_excptr;
74+ new_excptr = excptr;
75+ benchmark::DoNotOptimize (new_excptr);
76+ }
77+ }
78+ BENCHMARK (bm_exception_ptr_copy_assign_null);
79+
80+
81+ void bm_exception_ptr_move_assign_nonnull (benchmark::State& state) {
82+ std::exception_ptr excptr = std::make_exception_ptr (42 );
83+ for (auto _ : state) {
84+ benchmark::DoNotOptimize (excptr);
85+ std::exception_ptr new_excptr;
86+ new_excptr = std::move (excptr);
87+ benchmark::DoNotOptimize (new_excptr);
88+ }
89+ }
90+ BENCHMARK (bm_exception_ptr_move_assign_nonnull);
91+
92+ void bm_exception_ptr_move_assign_null (benchmark::State& state) {
93+ std::exception_ptr excptr = nullptr ;
94+ for (auto _ : state) {
95+ benchmark::DoNotOptimize (excptr);
96+ std::exception_ptr new_excptr;
97+ new_excptr = std::move (excptr);
98+ benchmark::DoNotOptimize (new_excptr);
99+ }
100+ }
101+ BENCHMARK (bm_exception_ptr_move_assign_null);
102+
103+ void bm_exception_ptr_swap_nonnull (benchmark::State& state) {
104+ std::exception_ptr excptr = std::make_exception_ptr (42 );
105+ for (auto _ : state) {
106+ benchmark::DoNotOptimize (excptr);
107+ std::exception_ptr new_excptr;
108+ swap (excptr, new_excptr);
109+ benchmark::DoNotOptimize (new_excptr);
110+ }
111+ }
112+ BENCHMARK (bm_exception_ptr_swap_nonnull);
113+
114+ void bm_exception_ptr_swap_null (benchmark::State& state) {
115+ std::exception_ptr excptr = nullptr ;
116+ for (auto _ : state) {
117+ benchmark::DoNotOptimize (excptr);
118+ std::exception_ptr new_excptr;
119+ swap (excptr, new_excptr);
120+ benchmark::DoNotOptimize (new_excptr);
121+ }
122+ }
123+ BENCHMARK (bm_exception_ptr_swap_null);
124+
125+ // A chain of moves, copies and swaps.
126+ // In contrast to the previous benchmarks of individual operations,
127+ // this benchmark performs a chain of operations. It thereby
128+ // specifically stresses the information available to the compiler
129+ // for optimizations from the header itself.
130+ static bool exception_ptr_move_copy_swap (std::exception_ptr p1) {
22131 // Taken from https://llvm.org/PR45547
23132 std::exception_ptr p2 (p1);
24133 std::exception_ptr p3 (std::move (p2));
@@ -33,34 +142,34 @@ static bool exception_ptr_moves_copies_swap(std::exception_ptr p1) {
33142}
34143
35144// Benchmark copies, moves and comparisons of a non-null exception_ptr.
36- void bm_nonnull_exception_ptr (benchmark::State& state) {
145+ void bm_exception_ptr_move_copy_swap_nonnull (benchmark::State& state) {
37146 std::exception_ptr excptr = std::make_exception_ptr (42 );
38147 for (auto _ : state) {
39148 benchmark::DoNotOptimize (excptr);
40- benchmark::DoNotOptimize (exception_ptr_moves_copies_swap (excptr));
149+ benchmark::DoNotOptimize (exception_ptr_move_copy_swap (excptr));
41150 }
42151}
43- BENCHMARK (bm_nonnull_exception_ptr );
152+ BENCHMARK (bm_exception_ptr_move_copy_swap_nonnull );
44153
45154// Benchmark copies, moves and comparisons of a nullptr exception_ptr
46155// where the compiler cannot prove that the exception_ptr is always
47156// a nullptr and needs to emit runtime checks.
48- void bm_null_exception_ptr (benchmark::State& state) {
157+ void bm_exception_ptr_move_copy_swap_null (benchmark::State& state) {
49158 std::exception_ptr excptr;
50159 for (auto _ : state) {
51160 benchmark::DoNotOptimize (excptr);
52- benchmark::DoNotOptimize (exception_ptr_moves_copies_swap (excptr));
161+ benchmark::DoNotOptimize (exception_ptr_move_copy_swap (excptr));
53162 }
54163}
55- BENCHMARK (bm_null_exception_ptr );
164+ BENCHMARK (bm_exception_ptr_move_copy_swap_null );
56165
57166// Benchmark copies, moves and comparisons of a nullptr exception_ptr
58167// where the compiler can proof that the exception_ptr is always a nullptr.
59- void bm_optimized_null_exception_ptr (benchmark::State& state) {
168+ void bm_exception_ptr_move_copy_swap_null_optimized (benchmark::State& state) {
60169 for (auto _ : state) {
61- benchmark::DoNotOptimize (exception_ptr_moves_copies_swap (std::exception_ptr{nullptr }));
170+ benchmark::DoNotOptimize (exception_ptr_move_copy_swap (std::exception_ptr{nullptr }));
62171 }
63172}
64- BENCHMARK (bm_optimized_null_exception_ptr );
173+ BENCHMARK (bm_exception_ptr_move_copy_swap_null_optimized );
65174
66175BENCHMARK_MAIN ();
0 commit comments