From c83dd5d60ef28fba30ca5abd9ae217a65b8d2300 Mon Sep 17 00:00:00 2001 From: Alexander Kiselev Date: Mon, 19 Mar 2018 19:17:26 +0300 Subject: [PATCH] Added: g3log, log4cplus, log4cpp, p7. Changes: boost, easylogging, g2log, glog, spdlog. --- bench/easyl-mt.conf | 10 ++++ bench/g3log-async.cpp | 62 +++++++++++++++++++++++ bench/log4cplus-bench-mt.cpp | 80 +++++++++++++++++++++++++++++ bench/log4cplus-bench.cpp | 54 ++++++++++++++++++++ bench/log4cpp-bench-mt.cpp | 74 +++++++++++++++++++++++++++ bench/log4cpp-bench.cpp | 48 ++++++++++++++++++ bench/p7-bench-mt.cpp | 97 ++++++++++++++++++++++++++++++++++++ bench/p7-bench.cpp | 70 ++++++++++++++++++++++++++ 8 files changed, 495 insertions(+) create mode 100644 bench/easyl-mt.conf create mode 100644 bench/g3log-async.cpp create mode 100644 bench/log4cplus-bench-mt.cpp create mode 100644 bench/log4cplus-bench.cpp create mode 100644 bench/log4cpp-bench-mt.cpp create mode 100644 bench/log4cpp-bench.cpp create mode 100644 bench/p7-bench-mt.cpp create mode 100644 bench/p7-bench.cpp diff --git a/bench/easyl-mt.conf b/bench/easyl-mt.conf new file mode 100644 index 00000000..8895b281 --- /dev/null +++ b/bench/easyl-mt.conf @@ -0,0 +1,10 @@ +* GLOBAL: + FORMAT = "[%datetime]: %msg" + FILENAME = ./logs/easylogging-mt.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/g3log-async.cpp b/bench/g3log-async.cpp new file mode 100644 index 00000000..b5e15a2b --- /dev/null +++ b/bench/g3log-async.cpp @@ -0,0 +1,62 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#include +#include +#include +#include +#include + +#include "g3log/g3log.hpp" +#include "g3log/logworker.hpp" + +using namespace std; +template std::string format(const T &value); + +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; + + auto worker = g3::LogWorker::createLogWorker(); + auto handle= worker->addDefaultLogger(argv[0], "logs"); + g3::initializeLogging(worker.get()); + + 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) << "g3log 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; + + 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; +} diff --git a/bench/log4cplus-bench-mt.cpp b/bench/log4cplus-bench-mt.cpp new file mode 100644 index 00000000..6acbf3fa --- /dev/null +++ b/bench/log4cplus-bench-mt.cpp @@ -0,0 +1,80 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#include +#include +#include +#include +#include +#include + +#include "log4cplus/logger.h" +#include "log4cplus/fileappender.h" +#include "log4cplus/layout.h" +#include "log4cplus/ndc.h" +#include "log4cplus/helpers/loglog.h" +#include "log4cplus/helpers/property.h" +#include "log4cplus/loggingmacros.h" + +using namespace log4cplus; + +int main(int argc, char * argv[]) +{ + using namespace std::chrono; + using clock = steady_clock; + + int thread_count = 10; + if (argc > 1) + thread_count = std::atoi(argv[1]); + + int howmany = 1000000; + + log4cplus::initialize(); + SharedFileAppenderPtr append( + new FileAppender(LOG4CPLUS_TEXT("logs/log4cplus-bench-mt.log"), std::ios_base::trunc, + true, true)); + append->setName(LOG4CPLUS_TEXT("File")); + + log4cplus::tstring pattern = LOG4CPLUS_TEXT("%d{%Y-%m-%d %H:%M:%S.%Q}: %p - %m %n"); + append->setLayout( std::auto_ptr(new PatternLayout(pattern)) ); + append->getloc(); + Logger::getRoot().addAppender(SharedAppenderPtr(append.get())); + + Logger root = Logger::getRoot(); + + std::atomic msg_counter{0}; + std::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; + LOG4CPLUS_INFO(root, "log4cplus 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; + + log4cplus::Logger::shutdown(); + return 0; +} diff --git a/bench/log4cplus-bench.cpp b/bench/log4cplus-bench.cpp new file mode 100644 index 00000000..e522e85a --- /dev/null +++ b/bench/log4cplus-bench.cpp @@ -0,0 +1,54 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#include +#include +#include + +#include "log4cplus/logger.h" +#include "log4cplus/fileappender.h" +#include "log4cplus/layout.h" +#include "log4cplus/ndc.h" +#include "log4cplus/helpers/loglog.h" +#include "log4cplus/helpers/property.h" +#include "log4cplus/loggingmacros.h" + +using namespace log4cplus; + +int main(int, char *[]) +{ + using namespace std::chrono; + using clock = steady_clock; + + int howmany = 1000000; + + log4cplus::initialize(); + SharedFileAppenderPtr append( + new FileAppender(LOG4CPLUS_TEXT("logs/log4cplus-bench.log"), std::ios_base::trunc, + true, true)); + append->setName(LOG4CPLUS_TEXT("File")); + + log4cplus::tstring pattern = LOG4CPLUS_TEXT("%d{%Y-%m-%d %H:%M:%S.%Q}: %p - %m %n"); + append->setLayout( std::auto_ptr(new PatternLayout(pattern)) ); + append->getloc(); + Logger::getRoot().addAppender(SharedAppenderPtr(append.get())); + + Logger root = Logger::getRoot(); + + auto start = clock::now(); + for (int i = 0; i < howmany; ++i) + LOG4CPLUS_INFO(root, "log4cplus 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; + + log4cplus::Logger::shutdown(); + return 0; +} diff --git a/bench/log4cpp-bench-mt.cpp b/bench/log4cpp-bench-mt.cpp new file mode 100644 index 00000000..82f3a40f --- /dev/null +++ b/bench/log4cpp-bench-mt.cpp @@ -0,0 +1,74 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#include +#include +#include +#include +#include +#include + +#include "log4cpp/Category.hh" +#include "log4cpp/Appender.hh" +#include "log4cpp/FileAppender.hh" +#include "log4cpp/Layout.hh" +#include "log4cpp/BasicLayout.hh" +#include "log4cpp/Priority.hh" +#include "log4cpp/PatternLayout.hh" + +int main(int argc, char * argv[]) +{ + using namespace std::chrono; + using clock = steady_clock; + + int thread_count = 10; + if (argc > 1) + thread_count = std::atoi(argv[1]); + + int howmany = 1000000; + + log4cpp::Appender *appender = new log4cpp::FileAppender("default", "logs/log4cpp-bench-mt.log"); + log4cpp::PatternLayout *layout = new log4cpp::PatternLayout(); + layout->setConversionPattern("{%Y-%m-%d %H:%M:%S.%l}: %p - %m %n"); + appender->setLayout(layout); + + log4cpp::Category& root = log4cpp::Category::getRoot(); + root.addAppender(appender); + root.setPriority(log4cpp::Priority::INFO); + + std::atomic msg_counter{0}; + std::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; + root << log4cpp::Priority::INFO << "log4cpp 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; + + root.shutdown(); + return 0; +} diff --git a/bench/log4cpp-bench.cpp b/bench/log4cpp-bench.cpp new file mode 100644 index 00000000..a21526c8 --- /dev/null +++ b/bench/log4cpp-bench.cpp @@ -0,0 +1,48 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#include +#include +#include + +#include "log4cpp/Category.hh" +#include "log4cpp/Appender.hh" +#include "log4cpp/FileAppender.hh" +#include "log4cpp/Layout.hh" +#include "log4cpp/BasicLayout.hh" +#include "log4cpp/Priority.hh" +#include "log4cpp/PatternLayout.hh" + +int main(int, char *[]) +{ + using namespace std::chrono; + using clock = steady_clock; + + int howmany = 1000000; + + log4cpp::Appender *appender = new log4cpp::FileAppender("default", "logs/log4cpp-bench.log"); + log4cpp::PatternLayout *layout = new log4cpp::PatternLayout(); + layout->setConversionPattern("%d{%Y-%m-%d %H:%M:%S.%l}: %p - %m %n"); + appender->setLayout(layout); + + log4cpp::Category& root = log4cpp::Category::getRoot(); + root.addAppender(appender); + root.setPriority(log4cpp::Priority::INFO); + + auto start = clock::now(); + for (int i = 0; i < howmany; ++i) + root << log4cpp::Priority::INFO << "log4cpp 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; + + root.shutdown(); + return 0; +} diff --git a/bench/p7-bench-mt.cpp b/bench/p7-bench-mt.cpp new file mode 100644 index 00000000..a3195208 --- /dev/null +++ b/bench/p7-bench-mt.cpp @@ -0,0 +1,97 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#include +#include +#include +#include +#include +#include +#include + +#include "P7_Trace.h" + + +int main(int argc, char *argv[]) +{ + using namespace std::chrono; + using clock = steady_clock; + + int thread_count = 10; + if (argc > 1) + thread_count = std::atoi(argv[1]); + + int howmany = 1000000; + + IP7_Trace::hModule module = NULL; + + //create P7 client object + std::unique_ptr> client( + P7_Create_Client(TM("/P7.Pool=1024 /P7.Sink=FileTxt /P7.Dir=logs/p7-bench-mt")), + [&](IP7_Client *ptr){ + if (ptr) + ptr->Release(); + }); + + if (!client) + { + std::cout << "Can't create IP7_Client" << std::endl; + return 1; + } + + //create P7 trace object 1 + std::unique_ptr> trace( + P7_Create_Trace(client.get(), TM("Trace channel 1")), + [&](IP7_Trace *ptr){ + if (ptr) + ptr->Release(); + }); + + if (!trace) + { + std::cout << "Can't create IP7_Trace" << std::endl; + return 1; + } + + trace->Register_Thread(TM("Application"), 0); + trace->Register_Module(TM("Main"), &module); + + std::atomic msg_counter{0}; + std::vector threads; + + auto start = clock::now(); + for (int t = 0; t < thread_count; ++t) + { + threads.push_back(std::thread([&]() { + trace->Register_Thread(TM("Application"), t+1); + while (true) + { + int counter = ++msg_counter; + if (counter > howmany) + break; + trace->P7_INFO(module, TM("p7 message #%d: This is some text for your pleasure"), counter); + } + trace->Register_Thread(TM("Application"), t+1); + })); + } + + 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; + + trace->Unregister_Thread(0); + + return 0; +} diff --git a/bench/p7-bench.cpp b/bench/p7-bench.cpp new file mode 100644 index 00000000..15513ca5 --- /dev/null +++ b/bench/p7-bench.cpp @@ -0,0 +1,70 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#include +#include +#include +#include + +#include "P7_Trace.h" + + +int main(int, char *[]) +{ + using namespace std::chrono; + using clock = steady_clock; + + int howmany = 1000000; + + IP7_Trace::hModule module = NULL; + + //create P7 client object + std::unique_ptr> client( + P7_Create_Client(TM("/P7.Pool=1024 /P7.Sink=FileTxt /P7.Dir=logs/p7-bench")), + [&](IP7_Client *ptr){ + if (ptr) + ptr->Release(); + }); + + if (!client) + { + std::cout << "Can't create IP7_Client" << std::endl; + return 1; + } + + //create P7 trace object 1 + std::unique_ptr> trace( + P7_Create_Trace(client.get(), TM("Trace channel 1")), + [&](IP7_Trace *ptr){ + if (ptr) + ptr->Release(); + }); + + if (!trace) + { + std::cout << "Can't create IP7_Trace" << std::endl; + return 1; + } + + trace->Register_Thread(TM("Application"), 0); + trace->Register_Module(TM("Main"), &module); + + auto start = clock::now(); + for (int i = 0; i < howmany; ++i) + trace->P7_INFO(module, TM("p7 message #%d: This is some text for your pleasure"), i); + + + 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; + + trace->Unregister_Thread(0); + + return 0; +}