From 971c1f46b087ba3944c85b92aad67dc8896ac803 Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 12 Nov 2018 11:07:51 +0200 Subject: [PATCH] Updated latency tests --- bench/Makefile | 12 ++++++------ bench/latency.cpp | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/bench/Makefile b/bench/Makefile index 11a1037b..181f4664 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -1,27 +1,27 @@ CXX ?= g++ -CXXFLAGS = -march=native -Wall -Wextra -pedantic -Wconversion -std=c++11 -pthread -I../include -fmax-errors=1 +CXXFLAGS = -march=native -Wall -Wextra -pedantic -Wconversion -std=c++11 -pthread -I../include -fmax-errors=1 CXX_RELEASE_FLAGS = -O3 -flto -Wl,--no-as-needed -binaries=padder_bench +binaries=bench.cpp async_bench latency padder_bench all: $(binaries) bench: bench.cpp $(CXX) bench.cpp -o bench $(CXXFLAGS) $(CXX_RELEASE_FLAGS) - + async_bench: async_bench.cpp $(CXX) async_bench.cpp -o async_bench $(CXXFLAGS) $(CXX_RELEASE_FLAGS) - - + + latency: latency.cpp $(CXX) latency.cpp -o latency $(CXXFLAGS) $(CXX_RELEASE_FLAGS) -lbenchmark padder_bench: padder_bench.cpp $(CXX) padder_bench.cpp -o padder_bench $(CXXFLAGS) $(CXX_RELEASE_FLAGS) -lbenchmark - + .PHONY: clean diff --git a/bench/latency.cpp b/bench/latency.cpp index 6df593dd..78ee1786 100644 --- a/bench/latency.cpp +++ b/bench/latency.cpp @@ -59,6 +59,18 @@ void bench_logger(benchmark::State &state, std::shared_ptr logge } } +void bench_disabled_macro(benchmark::State &state, std::shared_ptr logger) +{ + int i = 0; + benchmark::DoNotOptimize(i); //prevent unused warnings + benchmark::DoNotOptimize(logger); //prevent unused warnings + for (auto _ : state) + { + SPDLOG_LOGGER_DEBUG(logger, "Hello logger: msg number {}...............", i++); + SPDLOG_DEBUG("Hello logger: msg number {}...............", i++); + } +} + int main(int argc, char *argv[]) { @@ -74,14 +86,14 @@ int main(int argc, char *argv[]) prepare_logdir(); - // Single threaded benchmarks + // disabled loggers auto disabled_logger = std::make_shared("bench", std::make_shared()); disabled_logger->set_level(spdlog::level::off); - benchmark::RegisterBenchmark("disabled-level", bench_logger, disabled_logger)->UseRealTime(); + benchmark::RegisterBenchmark("disabled-at-compile-time", bench_disabled_macro, disabled_logger); + benchmark::RegisterBenchmark("disabled-at-runtime", bench_logger, disabled_logger); auto null_logger_st = std::make_shared("bench", std::make_shared()); - benchmark::RegisterBenchmark("null_sink_st (500_bytes c_str)", bench_c_string, std::move(null_logger_st))->UseRealTime(); - + benchmark::RegisterBenchmark("null_sink_st (500_bytes c_str)", bench_c_string, std::move(null_logger_st)); benchmark::RegisterBenchmark("null_sink_st", bench_logger, null_logger_st); // basic_st