From 604a5e46c6f527edd8648ccd6f75840a3934d496 Mon Sep 17 00:00:00 2001 From: Artur Mukhamadiev Date: Mon, 23 Jun 2025 00:00:14 +0300 Subject: [PATCH] additional benchmarks --- bench/CMakeLists.txt | 2 ++ bench/main.cc | 53 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index d48097f..d389f97 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -1,5 +1,6 @@ find_package(benchmark REQUIRED) +find_package(glog REQUIRED) set(NAME ${PROJECT_NAME}_bench) add_executable(${NAME} main.cc) @@ -7,6 +8,7 @@ add_executable(${NAME} main.cc) target_link_libraries(${NAME} PRIVATE benchmark::benchmark_main benchmark::benchmark + glog::glog ${PROJECT_NAME} ) diff --git a/bench/main.cc b/bench/main.cc index cc84ae6..d0d5caf 100644 --- a/bench/main.cc +++ b/bench/main.cc @@ -1,6 +1,10 @@ #include #include +#include +#include +#include #include "benchmark/benchmark.h" +#include "glog/logging.h" #include "logger.hh" //! AI generated @@ -51,6 +55,12 @@ vptyp::Logger& getLogger() { return l; } +void initGlog() { + if (!google::IsGoogleLoggingInitialized()) { + google::InitGoogleLogging("loggerBench"); + } +} + static void BM_taylor_logger(benchmark::State& state) { auto& l = getLogger(); for (auto _ : state) { @@ -64,8 +74,51 @@ static void BM_wo_logger(benchmark::State& state) { double res = calc_exp_taylor(); } +static void BM_taylor_glog(benchmark::State& state) { + initGlog(); + for (auto _ : state) { + double res = calc_exp_taylor(); + LOG(INFO) << "apprx=" << res; + } +} + +std::atomic& getValue() { + static std::atomic d; + return d; +} + +static void BM_taylor_atomic_upd(benchmark::State& state) { + for (auto _ : state) { + double res = calc_exp_taylor(); + getValue().store(res); + } +} + +void updValue(double res, const std::string& key) { + static std::unordered_map d = {{"key", 10.0}, + {"assembly", 11.0}, + {"draw", 123.3}, + {"d2", 0.0}, + {"d55", 0.23}}; + static std::mutex mtx; + { + std::lock_guard lock(mtx); + d[key] = res; + } +} + +static void BM_taylor_mutex_upd(benchmark::State& state) { + for (auto _ : state) { + double res = calc_exp_taylor(); + updValue(res, "assembly"); + } +} + BENCHMARK(BM_wo_logger); BENCHMARK(BM_taylor_logger); +BENCHMARK(BM_taylor_glog); +BENCHMARK(BM_taylor_atomic_upd); +BENCHMARK(BM_taylor_mutex_upd); std::string caesar_encoder(const std::string& input) { static constexpr int small = 'a';