-
Notifications
You must be signed in to change notification settings - Fork 15k
[libc++] Add benchmark for std::exception_ptr
#164278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
47823b9
2da8845
bb6480e
a799f0e
b81d32b
4cedc59
1096c42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,4 +18,49 @@ void bm_make_exception_ptr(benchmark::State& state) { | |
| } | ||
| BENCHMARK(bm_make_exception_ptr)->ThreadRange(1, 8); | ||
|
|
||
| static bool exception_ptr_moves_copies_swap(std::exception_ptr p1) { | ||
| // Taken from https://github.com/llvm/llvm-project/issues/44892 | ||
| std::exception_ptr p2(p1); // Copy constructor | ||
| std::exception_ptr p3(std::move(p2)); // Move constructor | ||
| p2 = std::move(p1); // Move assignment | ||
| p1 = p2; // Copy assignment | ||
| swap(p1, p2); // Swap | ||
vogelsgesang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Comparisons against nullptr. The overhead from creating temporary `exception_ptr` | ||
| // instances should be optimized out. | ||
| bool is_null = p1 == nullptr && nullptr == p2; | ||
| bool is_equal = p1 == p2; // Comparison | ||
| return is_null && is_equal; | ||
| } | ||
|
|
||
| void bm_nonnull_exception_ptr(benchmark::State& state) { | ||
| std::exception_ptr excptr = std::make_exception_ptr(42); | ||
| for (auto _ : state) { | ||
| benchmark::DoNotOptimize(excptr); | ||
| benchmark::DoNotOptimize(exception_ptr_moves_copies_swap(excptr)); | ||
| } | ||
| } | ||
| BENCHMARK(bm_nonnull_exception_ptr); | ||
|
|
||
| void bm_null_exception_ptr(benchmark::State& state) { | ||
| std::exception_ptr excptr; | ||
| for (auto _ : state) { | ||
| // All of the `exception_ptr_noops` are no-ops but the optimizer | ||
vogelsgesang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // cannot optimize them away, because the `DoNotOptimize` calls | ||
| // prevent the optimizer from doing so. | ||
| benchmark::DoNotOptimize(excptr); | ||
| benchmark::DoNotOptimize(exception_ptr_moves_copies_swap(excptr)); | ||
| } | ||
| } | ||
| BENCHMARK(bm_null_exception_ptr); | ||
|
|
||
| void bm_optimized_null_exception_ptr(benchmark::State& state) { | ||
|
||
| for (auto _ : state) { | ||
| // All of the `exception_ptr_noops` are no-ops because | ||
| // the exception_ptr is empty. Hence, the compiler should | ||
| // be able to optimize them very aggressively. | ||
| benchmark::DoNotOptimize(exception_ptr_moves_copies_swap(std::exception_ptr{nullptr})); | ||
| } | ||
| } | ||
| BENCHMARK(bm_optimized_null_exception_ptr); | ||
|
|
||
| BENCHMARK_MAIN(); | ||
Uh oh!
There was an error while loading. Please reload this page.