From 0f66c63f72b3b0b3e0ea9073d5bf47af02057172 Mon Sep 17 00:00:00 2001 From: Alexander Kiselev Date: Wed, 21 Mar 2018 16:46:52 +0300 Subject: [PATCH] Update easyloggingpp, Add plog --- bench/Makefile | 20 +++++++-- bench/easyl-async.conf | 10 +++++ bench/easyl-mt.conf | 2 +- bench/easyl.conf | 2 +- bench/easylogging-bench-async.cpp | 67 +++++++++++++++++++++++++++++++ bench/plog-bench-mt.cpp | 61 ++++++++++++++++++++++++++++ bench/plog-bench.cpp | 34 ++++++++++++++++ 7 files changed, 190 insertions(+), 6 deletions(-) create mode 100644 bench/easyl-async.conf create mode 100644 bench/easylogging-bench-async.cpp create mode 100644 bench/plog-bench-mt.cpp create mode 100644 bench/plog-bench.cpp diff --git a/bench/Makefile b/bench/Makefile index c619a5ae..8328c5cd 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -11,7 +11,8 @@ binaries=spdlog-bench spdlog-bench-mt spdlog-async spdlog-null-async \ p7-bench p7-bench-mt \ log4cpp-bench log4cpp-bench-mt \ log4cplus-bench log4cplus-bench-mt \ - easylogging-bench easylogging-bench-mt + easylogging-bench easylogging-bench-mt easylogging-bench-async \ + plog-bench plog-bench-mt all: $(binaries) @@ -22,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) + $(CXX) spdlog-async.cpp -o spdlog-async $(CXXFLAGS) $(CXX_RELEASE_FLAGS) -g spdlog-null-async: spdlog-null-async.cpp $(CXX) spdlog-null-async.cpp -o spdlog-null-async $(CXXFLAGS) $(CXX_RELEASE_FLAGS) @@ -74,9 +75,20 @@ log4cplus-bench-mt: log4cplus-bench-mt.cpp EASYL_FLAGS = -I$(HOME)/easyloggingpp/src easylogging-bench: easylogging-bench.cpp $(CXX) easylogging-bench.cpp -o easylogging-bench $(CXXFLAGS) $(EASYL_FLAGS) $(CXX_RELEASE_FLAGS) + easylogging-bench-mt: easylogging-bench-mt.cpp - $(CXX) easylogging-bench-mt.cpp -o easylogging-bench-mt $(CXXFLAGS) $(EASYL_FLAGS) $(CXX_RELEASE_FLAGS) - + $(CXX) easylogging-bench-mt.cpp -o easylogging-bench-mt $(CXXFLAGS) $(EASYL_FLAGS) $(CXX_RELEASE_FLAGS) + +easylogging-bench-async: easylogging-bench-async.cpp + $(CXX) easylogging-bench-async.cpp -o easylogging-bench-async $(CXXFLAGS) $(EASYL_FLAGS) $(CXX_RELEASE_FLAGS) + +PLOG_FLAGS = -I$(HOME)/include +plog-bench: plog-bench.cpp + $(CXX) plog-bench.cpp -o plog-bench $(CXXFLAGS) $(PLOG_FLAGS) $(CXX_RELEASE_FLAGS) + +plog-bench-mt: plog-bench-mt.cpp + $(CXX) plog-bench-mt.cpp -o plog-bench-mt $(CXXFLAGS) $(PLOG_FLAGS) $(CXX_RELEASE_FLAGS) + .PHONY: clean clean: diff --git a/bench/easyl-async.conf b/bench/easyl-async.conf new file mode 100644 index 00000000..a6c52050 --- /dev/null +++ b/bench/easyl-async.conf @@ -0,0 +1,10 @@ +* GLOBAL: + FORMAT = "[%datetime]: %levshort %thread %msg" + FILENAME = ./logs/easylogging-async.log + ENABLED = true + TO_FILE = true + TO_STANDARD_OUTPUT = false + MILLISECONDS_WIDTH = 3 + PERFORMANCE_TRACKING = false + MAX_LOG_FILE_SIZE = 10485760 + Log_Flush_Threshold = 10485760 diff --git a/bench/easyl-mt.conf b/bench/easyl-mt.conf index 8895b281..ceff467c 100644 --- a/bench/easyl-mt.conf +++ b/bench/easyl-mt.conf @@ -1,5 +1,5 @@ * GLOBAL: - FORMAT = "[%datetime]: %msg" + FORMAT = "[%datetime]: %levshort %thread %msg" FILENAME = ./logs/easylogging-mt.log ENABLED = true TO_FILE = true diff --git a/bench/easyl.conf b/bench/easyl.conf index 3bfb5440..c54f6c83 100644 --- a/bench/easyl.conf +++ b/bench/easyl.conf @@ -1,5 +1,5 @@ * GLOBAL: - FORMAT = "[%datetime]: %msg" + FORMAT = "[%datetime]: %levshort %msg" FILENAME = ./logs/easylogging.log ENABLED = true TO_FILE = true diff --git a/bench/easylogging-bench-async.cpp b/bench/easylogging-bench-async.cpp new file mode 100644 index 00000000..81985a6a --- /dev/null +++ b/bench/easylogging-bench-async.cpp @@ -0,0 +1,67 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#include +#include +#include +#include +#include + +#define ELPP_THREAD_SAFE +#define ELPP_EXPERIMENTAL_ASYNC +#include "easylogging++.h" +#include "easylogging++.cc" +INITIALIZE_EASYLOGGINGPP + +using namespace std; + +int main(int argc, char *argv[]) +{ + using namespace std::chrono; + using clock = steady_clock; + + int thread_count = 10; + if (argc > 1) + thread_count = atoi(argv[1]); + + int howmany = 1000000; + + // Load configuration from file + el::Configurations conf("easyl-async.conf"); + el::Loggers::reconfigureLogger("default", conf); + + std::atomic msg_counter{0}; + vector threads; + + 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; + LOG(INFO) << "easylog message #" << counter << ": This is some text for your pleasure"; + } + })); + } + + for (auto &t : threads) + { + t.join(); + } + + 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 = " << deltaf << " seconds" << std::endl; + std::cout << "Rate = " << rate << "/sec" << std::endl; + + return 0; +} diff --git a/bench/plog-bench-mt.cpp b/bench/plog-bench-mt.cpp new file mode 100644 index 00000000..5951643f --- /dev/null +++ b/bench/plog-bench-mt.cpp @@ -0,0 +1,61 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#include +#include +#include +#include +#include + +#include "plog/Log.h" + +using namespace std; + +int main(int argc, char *argv[]) +{ + using namespace std::chrono; + using clock = steady_clock; + + int thread_count = 10; + if (argc > 1) + thread_count = atoi(argv[1]); + + int howmany = 1000000; + + plog::init(plog::debug, "logs/plog-bench-mt.log"); + + std::atomic msg_counter{0}; + vector threads; + + 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; + LOG_INFO << "plog message #" << counter << ": This is some text for your pleasure"; + } + })); + } + + for (auto &t : threads) + { + t.join(); + } + + 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 = " << deltaf << " seconds" << std::endl; + std::cout << "Rate = " << rate << "/sec" << std::endl; + + return 0; +} diff --git a/bench/plog-bench.cpp b/bench/plog-bench.cpp new file mode 100644 index 00000000..3e017fc7 --- /dev/null +++ b/bench/plog-bench.cpp @@ -0,0 +1,34 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#include +#include +#include + +#include "plog/Log.h" + +int main(int, char *[]) +{ + using namespace std::chrono; + using clock = steady_clock; + + int howmany = 1000000; + + plog::init(plog::debug, "logs/plog-bench.log"); + + auto start = clock::now(); + for (int i = 0; i < howmany; ++i) + LOG_INFO << "plog message #" << i << ": This is some text for your pleasure"; + + duration delta = clock::now() - start; + float deltaf = delta.count(); + auto rate = howmany / deltaf; + + std::cout << "Total: " << howmany << std::endl; + std::cout << "Delta = " << deltaf << " seconds" << std::endl; + std::cout << "Rate = " << rate << "/sec" << std::endl; + + return 0; +}