diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp index 3eb99ab57f5..9b74af51bfa 100644 --- a/src/bench/bench.cpp +++ b/src/bench/bench.cpp @@ -5,25 +5,19 @@ #include #include // IWYU pragma: keep -#include #include -#include #include #include #include #include #include -#include -#include #include -#include -#include #include +#include #include using namespace std::chrono_literals; -using util::Join; const std::function G_TEST_LOG_FUN{}; @@ -69,37 +63,15 @@ void GenerateTemplateResults(const std::vector& bench namespace benchmark { -// map a label to one or multiple priority levels -std::map map_label_priority = { - {"high", PriorityLevel::HIGH}, - {"low", PriorityLevel::LOW}, - {"all", 0xff} -}; - -std::string ListPriorities() -{ - using item_t = std::pair; - auto sort_by_priority = [](item_t a, item_t b){ return a.second < b.second; }; - std::set sorted_priorities(map_label_priority.begin(), map_label_priority.end(), sort_by_priority); - return Join(sorted_priorities, ',', [](const auto& entry){ return entry.first; }); -} - -uint8_t StringToPriority(const std::string& str) -{ - auto it = map_label_priority.find(str); - if (it == map_label_priority.end()) throw std::runtime_error(strprintf("Unknown priority level %s", str)); - return it->second; -} - BenchRunner::BenchmarkMap& BenchRunner::benchmarks() { static BenchmarkMap benchmarks_map; return benchmarks_map; } -BenchRunner::BenchRunner(std::string name, BenchFunction func, PriorityLevel level) +BenchRunner::BenchRunner(std::string name, BenchFunction func) { - benchmarks().insert(std::make_pair(name, std::make_pair(func, level))); + benchmarks().insert(std::make_pair(name, func)); } void BenchRunner::RunAll(const Args& args) @@ -120,12 +92,7 @@ void BenchRunner::RunAll(const Args& args) }; std::vector benchmarkResults; - for (const auto& [name, bench_func] : benchmarks()) { - const auto& [func, priority_level] = bench_func; - - if (!(priority_level & args.priority)) { - continue; - } + for (const auto& [name, func] : benchmarks()) { if (!std::regex_match(name, baseMatch, reFilter)) { continue; diff --git a/src/bench/bench.h b/src/bench/bench.h index f6c41486643..8dfd8a77956 100644 --- a/src/bench/bench.h +++ b/src/bench/bench.h @@ -10,11 +10,9 @@ #include #include -#include #include #include #include -#include #include /* @@ -42,16 +40,6 @@ using ankerl::nanobench::Bench; typedef std::function BenchFunction; -enum PriorityLevel : uint8_t -{ - LOW = 1 << 0, - HIGH = 1 << 2, -}; - -// List priority labels, comma-separated and sorted by increasing priority -std::string ListPriorities(); -uint8_t StringToPriority(const std::string& str); - struct Args { bool is_list_only; bool sanity_check; @@ -60,25 +48,24 @@ struct Args { fs::path output_csv; fs::path output_json; std::string regex_filter; - uint8_t priority; std::vector setup_args; }; class BenchRunner { - // maps from "name" -> (function, priority_level) - typedef std::map> BenchmarkMap; + // maps from "name" -> function + using BenchmarkMap = std::map; static BenchmarkMap& benchmarks(); public: - BenchRunner(std::string name, BenchFunction func, PriorityLevel level); + BenchRunner(std::string name, BenchFunction func); static void RunAll(const Args& args); }; } // namespace benchmark -// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo("foo", foo, priority_level); +// BENCHMARK(foo) expands to: benchmark::BenchRunner bench_11foo{"foo", foo}; #define BENCHMARK(n, priority_level) \ - benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n))(STRINGIZE(n), n, priority_level); + benchmark::BenchRunner PASTE2(bench_, PASTE2(__LINE__, n)){STRINGIZE(n), n}; #endif // BITCOIN_BENCH_BENCH_H diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp index 841d6258df8..987523a128b 100644 --- a/src/bench/bench_bitcoin.cpp +++ b/src/bench/bench_bitcoin.cpp @@ -18,12 +18,8 @@ #include #include -using util::SplitString; - static const char* DEFAULT_BENCH_FILTER = ".*"; static constexpr int64_t DEFAULT_MIN_TIME_MS{10}; -/** Priority level default value, run "all" priority levels */ -static const std::string DEFAULT_PRIORITY{"all"}; static void SetupBenchArgs(ArgsManager& argsman) { @@ -37,8 +33,6 @@ static void SetupBenchArgs(ArgsManager& argsman) argsman.AddArg("-output-csv=", "Generate CSV file with the most important benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-output-json=", "Generate JSON file with all benchmark results", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-sanity-check", "Run benchmarks for only one iteration with no output", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); - argsman.AddArg("-priority-level=", strprintf("Run benchmarks of one or multiple priority level(s) (%s), default: '%s'", - benchmark::ListPriorities(), DEFAULT_PRIORITY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); } // parses a comma separated list like "10,20,30,50" @@ -54,14 +48,6 @@ static std::vector parseAsymptote(const std::string& str) { return numbers; } -static uint8_t parsePriorityLevel(const std::string& str) { - uint8_t levels{0}; - for (const auto& level: SplitString(str, ',')) { - levels |= benchmark::StringToPriority(level); - } - return levels; -} - static std::vector parseTestSetupArgs(const ArgsManager& argsman) { // Parses unit test framework arguments supported by the benchmark framework. @@ -144,7 +130,6 @@ int main(int argc, char** argv) args.output_json = argsman.GetPathArg("-output-json"); args.regex_filter = argsman.GetArg("-filter", DEFAULT_BENCH_FILTER); args.sanity_check = argsman.GetBoolArg("-sanity-check", false); - args.priority = parsePriorityLevel(argsman.GetArg("-priority-level", DEFAULT_PRIORITY)); args.setup_args = parseTestSetupArgs(argsman); benchmark::BenchRunner::RunAll(args);