2022-12-24 23:49:50 +00:00
|
|
|
// Copyright (c) 2020-2022 The Bitcoin Core developers
|
2020-04-29 15:05:41 +02:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <bench/bench.h>
|
|
|
|
#include <logging.h>
|
|
|
|
#include <test/util/setup_common.h>
|
2023-04-17 22:20:59 +02:00
|
|
|
#include <util/chaintype.h>
|
2020-04-29 15:05:41 +02:00
|
|
|
|
2023-01-23 07:49:46 -08:00
|
|
|
// All but 2 of the benchmarks should have roughly similar performance:
|
|
|
|
//
|
|
|
|
// LogPrintWithoutCategory should be ~3 orders of magnitude faster, as nothing is logged.
|
|
|
|
//
|
|
|
|
// LogWithoutWriteToFile should be ~2 orders of magnitude faster, as it avoids disk writes.
|
2020-04-29 15:05:41 +02:00
|
|
|
|
|
|
|
static void Logging(benchmark::Bench& bench, const std::vector<const char*>& extra_args, const std::function<void()>& log)
|
|
|
|
{
|
2023-01-30 07:21:36 -08:00
|
|
|
// Reset any enabled logging categories from a previous benchmark run.
|
|
|
|
LogInstance().DisableCategory(BCLog::LogFlags::ALL);
|
|
|
|
|
2020-04-29 15:05:41 +02:00
|
|
|
TestingSetup test_setup{
|
2023-04-17 22:20:59 +02:00
|
|
|
ChainType::REGTEST,
|
2020-04-29 15:05:41 +02:00
|
|
|
extra_args,
|
|
|
|
};
|
|
|
|
|
|
|
|
bench.run([&] { log(); });
|
|
|
|
}
|
|
|
|
|
2022-07-11 10:58:29 +02:00
|
|
|
static void LogPrintLevelWithThreadNames(benchmark::Bench& bench)
|
|
|
|
{
|
|
|
|
Logging(bench, {"-logthreadnames=1", "-debug=net"}, [] {
|
|
|
|
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", "test"); });
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LogPrintLevelWithoutThreadNames(benchmark::Bench& bench)
|
|
|
|
{
|
|
|
|
Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] {
|
|
|
|
LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", "test"); });
|
|
|
|
}
|
|
|
|
|
2022-07-11 11:15:26 +02:00
|
|
|
static void LogPrintWithCategory(benchmark::Bench& bench)
|
2020-04-29 15:05:41 +02:00
|
|
|
{
|
|
|
|
Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] { LogPrint(BCLog::NET, "%s\n", "test"); });
|
|
|
|
}
|
2022-07-11 11:23:45 +02:00
|
|
|
|
2022-07-11 11:15:26 +02:00
|
|
|
static void LogPrintWithoutCategory(benchmark::Bench& bench)
|
2020-04-29 15:05:41 +02:00
|
|
|
{
|
|
|
|
Logging(bench, {"-logthreadnames=0", "-debug=0"}, [] { LogPrint(BCLog::NET, "%s\n", "test"); });
|
|
|
|
}
|
2022-07-11 11:23:45 +02:00
|
|
|
|
2022-07-11 10:58:29 +02:00
|
|
|
static void LogPrintfCategoryWithThreadNames(benchmark::Bench& bench)
|
|
|
|
{
|
|
|
|
Logging(bench, {"-logthreadnames=1", "-debug=net"}, [] {
|
|
|
|
LogPrintfCategory(BCLog::NET, "%s\n", "test");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LogPrintfCategoryWithoutThreadNames(benchmark::Bench& bench)
|
|
|
|
{
|
|
|
|
Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] {
|
|
|
|
LogPrintfCategory(BCLog::NET, "%s\n", "test");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-11 11:23:45 +02:00
|
|
|
static void LogPrintfWithThreadNames(benchmark::Bench& bench)
|
|
|
|
{
|
|
|
|
Logging(bench, {"-logthreadnames=1"}, [] { LogPrintf("%s\n", "test"); });
|
|
|
|
}
|
|
|
|
|
|
|
|
static void LogPrintfWithoutThreadNames(benchmark::Bench& bench)
|
|
|
|
{
|
|
|
|
Logging(bench, {"-logthreadnames=0"}, [] { LogPrintf("%s\n", "test"); });
|
|
|
|
}
|
|
|
|
|
2022-07-11 11:15:26 +02:00
|
|
|
static void LogWithoutWriteToFile(benchmark::Bench& bench)
|
2020-04-29 15:05:41 +02:00
|
|
|
{
|
2023-01-23 07:49:46 -08:00
|
|
|
// Disable writing the log to a file, as used for unit tests and fuzzing in `MakeNoLogFileContext`.
|
2020-04-29 15:05:41 +02:00
|
|
|
Logging(bench, {"-nodebuglogfile", "-debug=1"}, [] {
|
|
|
|
LogPrintf("%s\n", "test");
|
|
|
|
LogPrint(BCLog::NET, "%s\n", "test");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-11 10:58:29 +02:00
|
|
|
BENCHMARK(LogPrintLevelWithThreadNames, benchmark::PriorityLevel::HIGH);
|
|
|
|
BENCHMARK(LogPrintLevelWithoutThreadNames, benchmark::PriorityLevel::HIGH);
|
2022-07-11 11:15:26 +02:00
|
|
|
BENCHMARK(LogPrintWithCategory, benchmark::PriorityLevel::HIGH);
|
|
|
|
BENCHMARK(LogPrintWithoutCategory, benchmark::PriorityLevel::HIGH);
|
2022-07-11 10:58:29 +02:00
|
|
|
BENCHMARK(LogPrintfCategoryWithThreadNames, benchmark::PriorityLevel::HIGH);
|
|
|
|
BENCHMARK(LogPrintfCategoryWithoutThreadNames, benchmark::PriorityLevel::HIGH);
|
2022-07-11 11:23:45 +02:00
|
|
|
BENCHMARK(LogPrintfWithThreadNames, benchmark::PriorityLevel::HIGH);
|
|
|
|
BENCHMARK(LogPrintfWithoutThreadNames, benchmark::PriorityLevel::HIGH);
|
2022-07-11 11:15:26 +02:00
|
|
|
BENCHMARK(LogWithoutWriteToFile, benchmark::PriorityLevel::HIGH);
|