additional benchmarks

This commit is contained in:
Artur Mukhamadiev 2025-06-23 00:00:14 +03:00
parent 85f0f924f5
commit 604a5e46c6
2 changed files with 55 additions and 0 deletions

View File

@ -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}
)

View File

@ -1,6 +1,10 @@
#include <cmath>
#include <functional>
#include <mutex>
#include <thread>
#include <unordered_map>
#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<double>& getValue() {
static std::atomic<double> 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<std::string, double> 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';