From 37f209079e5108f70689766c32c0c1b9e15c7cd7 Mon Sep 17 00:00:00 2001 From: Alexander Kiselev Date: Wed, 21 Mar 2018 16:50:45 +0300 Subject: [PATCH] Update spdlog-bench --- bench/Makefile | 2 +- bench/spdlog-async.cpp | 73 +++++++++++++++++++++++---------------- bench/spdlog-bench-mt.cpp | 6 ++-- bench/spdlog-bench.cpp | 6 ++-- 4 files changed, 51 insertions(+), 36 deletions(-) diff --git a/bench/Makefile b/bench/Makefile index 8328c5cd..0dd4b19d 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -23,7 +23,7 @@ spdlog-bench-mt: spdlog-bench-mt.cpp $(CXX) spdlog-bench-mt.cpp -o spdlog-bench-mt $(CXXFLAGS) $(CXX_RELEASE_FLAGS) spdlog-async: spdlog-async.cpp - $(CXX) spdlog-async.cpp -o spdlog-async $(CXXFLAGS) $(CXX_RELEASE_FLAGS) -g + $(CXX) spdlog-async.cpp -o spdlog-async $(CXXFLAGS) $(CXX_RELEASE_FLAGS) spdlog-null-async: spdlog-null-async.cpp $(CXX) spdlog-null-async.cpp -o spdlog-null-async $(CXXFLAGS) $(CXX_RELEASE_FLAGS) diff --git a/bench/spdlog-async.cpp b/bench/spdlog-async.cpp index 1c0ce41d..e1d1a95f 100644 --- a/bench/spdlog-async.cpp +++ b/bench/spdlog-async.cpp @@ -3,14 +3,15 @@ // Distributed under the MIT License (http://opensource.org/licenses/MIT) // -#include "spdlog/spdlog.h" #include #include -#include #include +#include #include #include +#include "spdlog/spdlog.h" + using namespace std; int main(int argc, char *argv[]) @@ -20,42 +21,56 @@ int main(int argc, char *argv[]) int thread_count = 10; if (argc > 1) - thread_count = ::atoi(argv[1]); + thread_count = std::atoi(argv[1]); int howmany = 1000000; spdlog::set_async_mode(1048576); auto logger = spdlog::create("file_logger", "logs/spdlog-bench-async.log", false); - logger->set_pattern("[%Y-%b-%d %T.%e]: %f"); + logger->set_pattern("[%Y-%m-%d %T.%F]: %L %t %v"); - std::atomic msg_counter{0}; - vector threads; + std::cout << "To stop, press " << std::endl; + std::atomic run{true}; + std::thread stoper(std::thread([&run]() { + std::cin.get(); + run = false; + })); - auto start = clock::now(); - for (int t = 0; t < thread_count; ++t) + while(run) { - threads.push_back(std::thread([&]() { - while (true) - { - int counter = ++msg_counter; - if (counter > howmany) - break; - logger->info("spdlog message #{}: This is some text for your pleasure", counter); - } - })); - } + std::atomic msg_counter{0}; + std::vector threads; - for (auto &t : threads) - { - t.join(); - } + auto start = clock::now(); + for (int t = 0; t < thread_count; ++t) + { + threads.push_back(std::thread([&]() { + while (true) + { + int counter = ++msg_counter; + if (counter > howmany) + break; + logger->info("spdlog message #{}: This is some text for your pleasure", counter); + } + })); + } - duration delta = clock::now() - start; - float deltaf = delta.count(); - auto rate = howmany / deltaf; + for (auto &t : threads) + { + t.join(); + } - cout << "Total: " << howmany << std::endl; - cout << "Threads: " << thread_count << std::endl; - std::cout << "Delta = " << deltaf << " seconds" << std::endl; - std::cout << "Rate = " << rate << "/sec" << std::endl; + duration delta = clock::now() - start; + float deltaf = delta.count(); + auto rate = howmany / deltaf; + + std::cout << "Total: " << howmany << std::endl; + std::cout << "Threads: " << thread_count << std::endl; + std::cout << "Delta = " << std::fixed << deltaf << " seconds" << std::endl; + std::cout << "Rate = " << std::fixed << rate << "/sec" << std::endl; + } //while + + stoper.join(); + + return 0; } diff --git a/bench/spdlog-bench-mt.cpp b/bench/spdlog-bench-mt.cpp index d6dfeb51..b4948e73 100644 --- a/bench/spdlog-bench-mt.cpp +++ b/bench/spdlog-bench-mt.cpp @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) int howmany = 1000000; auto logger = spdlog::create("file_logger", "logs/spdlog-bench-mt.log", false); - logger->set_pattern("[%Y-%b-%d %T.%f]: %v"); + logger->set_pattern("[%Y-%m-%d %T.%F]: %L %t %v"); std::atomic msg_counter{0}; std::vector threads; @@ -56,8 +56,8 @@ int main(int argc, char *argv[]) std::cout << "Total: " << howmany << std::endl; std::cout << "Threads: " << thread_count << std::endl; - std::cout << "Delta = " << deltaf << " seconds" << std::endl; - std::cout << "Rate = " << rate << "/sec" << std::endl; + std::cout << "Delta = " << std::fixed << deltaf << " seconds" << std::endl; + std::cout << "Rate = " << std::fixed << rate << "/sec" << std::endl; return 0; } diff --git a/bench/spdlog-bench.cpp b/bench/spdlog-bench.cpp index e241fa5e..bb8a5ef8 100644 --- a/bench/spdlog-bench.cpp +++ b/bench/spdlog-bench.cpp @@ -16,7 +16,7 @@ int main(int, char *[]) int howmany = 1000000; auto logger = spdlog::create("file_logger", "logs/spdlog-bench.log", false); - logger->set_pattern("[%Y-%b-%d %T.%f]: %v"); + logger->set_pattern("[%Y-%m-%d %T.%F]: %L %v"); auto start = clock::now(); for (int i = 0; i < howmany; ++i) @@ -27,8 +27,8 @@ int main(int, char *[]) auto rate = howmany / deltaf; std::cout << "Total: " << howmany << std::endl; - std::cout << "Delta = " << deltaf << " seconds" << std::endl; - std::cout << "Rate = " << rate << "/sec" << std::endl; + std::cout << "Delta = " << std::fixed << deltaf << " seconds" << std::endl; + std::cout << "Rate = " << std::fixed << rate << "/sec" << std::endl; return 0; }