Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2020-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <bench/bench.h>6#include <logging.h>7#include <test/util/setup_common.h>9#include <functional>10#include <vector>12// All but 2 of the benchmarks should have roughly similar performance:13//14// LogWithoutDebug should be ~3 orders of magnitude faster, as nothing is logged.15//16// LogWithoutWriteToFile should be ~2 orders of magnitude faster, as it avoids disk writes.18static void Logging(benchmark::Bench& bench, const std::vector<const char*>& extra_args, const std::function<void()>& log)19{20// Reset any enabled logging categories from a previous benchmark run.21LogInstance().DisableCategory(BCLog::LogFlags::ALL);23TestingSetup test_setup{24ChainType::REGTEST,25{.extra_args = extra_args},26};28bench.run([&] { log(); });29}31static void LogWithDebug(benchmark::Bench& bench)32{33Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] { LogDebug(BCLog::NET, "%s\n", "test"); });34}36static void LogWithoutDebug(benchmark::Bench& bench)37{38Logging(bench, {"-logthreadnames=0", "-debug=0"}, [] { LogDebug(BCLog::NET, "%s\n", "test"); });39}41static void LogWithThreadNames(benchmark::Bench& bench)42{43Logging(bench, {"-logthreadnames=1"}, [] { LogInfo("%s\n", "test"); });44}46static void LogWithoutThreadNames(benchmark::Bench& bench)47{48Logging(bench, {"-logthreadnames=0"}, [] { LogInfo("%s\n", "test"); });49}51static void LogWithoutWriteToFile(benchmark::Bench& bench)52{53// Disable writing the log to a file, as used for unit tests and fuzzing in `MakeNoLogFileContext`.54Logging(bench, {"-nodebuglogfile", "-debug=1"}, [] {55LogInfo("%s\n", "test");56LogDebug(BCLog::NET, "%s\n", "test");57});58}60BENCHMARK(LogWithDebug);61BENCHMARK(LogWithoutDebug);62BENCHMARK(LogWithThreadNames);63BENCHMARK(LogWithoutThreadNames);64BENCHMARK(LogWithoutWriteToFile);
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.