catch2/benchmarks/catch_benchmarks.cpp
2025-01-17 18:02:13 -06:00

26 lines
492 B
C++

#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();
};
}