diff --git a/bench/Makefile b/bench/Makefile index c619a5ae..0dd4b19d 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) @@ -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/README.md b/bench/README.md new file mode 100644 index 00000000..aed6ee9b --- /dev/null +++ b/bench/README.md @@ -0,0 +1,14 @@ +# loggers + +Name | License | Lang. | Year | Platform | Compiler | Dependence | URL +--- | --- | --- | --- | --- | --- | --- | --- +Pantheios | BSD | C++ | 2017 | Windows, Linux, MacOSX | VC++, GCC(3.2+), Intel, Borland, Comeau, Digital Mars, Metrowerks | STLSoft | http://www.pantheios.org/
http://blog.pantheios.org/
https://github.com/synesissoftware/Pantheios
http://www.pantheios.org/performance.html +Glog | 3-clause BSD| C++| 2017 | Windows, Linux, MacOSX | VC++, GCC, Clang, intel| Google gflags | https://github.com/google/glog +G3log | Public Domain | C++11 | 2018 | Windows, Linux, MacOSX, iPhoneOS | VC++, GCC, Clang, MinGW | None | https://github.com/KjellKod/g3log
https://github.com/KjellKod/g3sinks
https://kjellkod.wordpress.com/2014/08/16/presenting-g3log-the-next-version-of-the-next-generation-of-loggers/
https://kjellkod.wordpress.com/2015/06/30/the-worlds-fastest-logger-vs-g3log/ +P7 | LGPL | C++, C, C#, Python | 2017 | Windows, Linux | VC++, GCC, Clang, MinGW | None | http://baical.net/p7.html +log4cpp | LGPL | C++ | 2017 | Windows, Linux, MacOSX | VC++, GCC, Sun CC, OpenVMS | Boost | http://log4cpp.sourceforge.net/ +log4cplus | 2-clause BSD or Apache 2 | C++ | 2017 | Windows, Linux, MacOSX, Android | VC++, GCC, Clang | Boost | https://github.com/log4cplus/log4cplus
https://sourceforge.net/p/log4cplus/wiki/Home/ +Easylogging | MIT | C++11 | 2018 | Windows, Linux, MacOSX, iPhoneOS, Android | VC++, GCC, Clang, Intel, MinGW | None | https://github.com/muflihun/easyloggingpp +Spdlog | MIT | C++11 | 2018 | Windows, Linux, MacOSX, iPhoneOS, Android(logcat) | VC++, GCC, Clang, MinGW | None, Headers only library | https://github.com/gabime/spdlog
https://github.com/fmtlib/fmt +Boost.Log v2 | Boost | C++ | 2016 | Windows, Linux, MacOSX, iPhoneOS, Android | VC++, GCC, Clang | Boost | https://github.com/boostorg/log
http://www.boost.org/doc/libs/1_66_0/libs/log/doc/html/index.html +plog | MPL 2.0 | C++ | 2017 | Windows, Linux, MacOSX, iPhoneOS, Android | gcc, clang, msvc, mingw, mingw-w64, icc, c++builder | None, Headers only library | https://github.com/SergiusTheBest/plog 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/p7-bench b/bench/p7-bench deleted file mode 100755 index 566ec56b..00000000 Binary files a/bench/p7-bench and /dev/null differ 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; +} 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; }