mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 15:50:07 +01:00
bench: Remove incorrect __LINE__ in BENCHMARK macro
Duplicate benchmarks with the same name are not supported. Expanding the name with __LINE__ is confusing and brittle, because it makes duplication bugs silent. Fix this twofold: * By enforcing unique benchmarks at compile-time and link-time. For example, a link failure may now look like: "mold: error: duplicate symbol: bench_runner_AddrManAdd" * By enforcing unique benchmarks at run-time. This should never happen, due to the build-failure, but a failure may look like: "Assertion `benchmarks().try_emplace(std::move(name), std::move(func)).second' failed."
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <bench/bench.h>
|
||||
|
||||
#include <test/util/setup_common.h> // IWYU pragma: keep
|
||||
#include <util/check.h>
|
||||
#include <util/fs.h>
|
||||
|
||||
#include <chrono>
|
||||
@@ -71,7 +72,7 @@ BenchRunner::BenchmarkMap& BenchRunner::benchmarks()
|
||||
|
||||
BenchRunner::BenchRunner(std::string name, BenchFunction func)
|
||||
{
|
||||
benchmarks().insert(std::make_pair(name, func));
|
||||
Assert(benchmarks().try_emplace(std::move(name), std::move(func)).second);
|
||||
}
|
||||
|
||||
void BenchRunner::RunAll(const Args& args)
|
||||
|
||||
@@ -64,8 +64,8 @@ public:
|
||||
};
|
||||
} // namespace benchmark
|
||||
|
||||
// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo{"foo", foo};
|
||||
// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_runner_foo{"foo", foo};
|
||||
#define BENCHMARK(n) \
|
||||
benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n)){STRINGIZE(n), n};
|
||||
benchmark::BenchRunner PASTE2(bench_runner_, n){STRINGIZE(n), n};
|
||||
|
||||
#endif // BITCOIN_BENCH_BENCH_H
|
||||
|
||||
Reference in New Issue
Block a user