additional benchmarks
This commit is contained in:
parent
85f0f924f5
commit
604a5e46c6
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
find_package(benchmark REQUIRED)
|
find_package(benchmark REQUIRED)
|
||||||
|
find_package(glog REQUIRED)
|
||||||
set(NAME ${PROJECT_NAME}_bench)
|
set(NAME ${PROJECT_NAME}_bench)
|
||||||
|
|
||||||
add_executable(${NAME} main.cc)
|
add_executable(${NAME} main.cc)
|
||||||
@ -7,6 +8,7 @@ add_executable(${NAME} main.cc)
|
|||||||
target_link_libraries(${NAME} PRIVATE
|
target_link_libraries(${NAME} PRIVATE
|
||||||
benchmark::benchmark_main
|
benchmark::benchmark_main
|
||||||
benchmark::benchmark
|
benchmark::benchmark
|
||||||
|
glog::glog
|
||||||
${PROJECT_NAME}
|
${PROJECT_NAME}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <mutex>
|
||||||
|
#include <thread>
|
||||||
|
#include <unordered_map>
|
||||||
#include "benchmark/benchmark.h"
|
#include "benchmark/benchmark.h"
|
||||||
|
#include "glog/logging.h"
|
||||||
#include "logger.hh"
|
#include "logger.hh"
|
||||||
|
|
||||||
//! AI generated
|
//! AI generated
|
||||||
@ -51,6 +55,12 @@ vptyp::Logger& getLogger() {
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initGlog() {
|
||||||
|
if (!google::IsGoogleLoggingInitialized()) {
|
||||||
|
google::InitGoogleLogging("loggerBench");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void BM_taylor_logger(benchmark::State& state) {
|
static void BM_taylor_logger(benchmark::State& state) {
|
||||||
auto& l = getLogger();
|
auto& l = getLogger();
|
||||||
for (auto _ : state) {
|
for (auto _ : state) {
|
||||||
@ -64,8 +74,51 @@ static void BM_wo_logger(benchmark::State& state) {
|
|||||||
double res = calc_exp_taylor();
|
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_wo_logger);
|
||||||
BENCHMARK(BM_taylor_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) {
|
std::string caesar_encoder(const std::string& input) {
|
||||||
static constexpr int small = 'a';
|
static constexpr int small = 'a';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user