mirror of
https://github.com/catchorg/Catch2.git
synced 2025-09-16 10:05:39 +02:00
Make assertions thread-safe
This commit is contained in:
3
benchmarks/CMakeLists.txt
Normal file
3
benchmarks/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
add_executable(benchmarks catch_benchmarks.cpp)
|
||||
target_link_libraries(benchmarks PRIVATE Catch2WithMain)
|
||||
target_compile_features(benchmarks PUBLIC cxx_std_17)
|
25
benchmarks/catch_benchmarks.cpp
Normal file
25
benchmarks/catch_benchmarks.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/benchmark/catch_benchmark.hpp>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
std::recursive_mutex global_lock;
|
||||
|
||||
int no_lock() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
int take_lock() {
|
||||
std::unique_lock<std::recursive_mutex> lock(global_lock);
|
||||
return 2;
|
||||
}
|
||||
|
||||
TEST_CASE("std::recursive_mutex overhead benchmark", "[benchmark][mutex]") {
|
||||
BENCHMARK("no lock") {
|
||||
return no_lock();
|
||||
};
|
||||
|
||||
BENCHMARK("with std::recursive_mutex") {
|
||||
return take_lock();
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user