From 350ff13d77c439ef27a17b755b0f8d56749fa5ea Mon Sep 17 00:00:00 2001 From: "Kevin M. Godby" Date: Wed, 4 May 2016 23:33:38 -0500 Subject: [PATCH] Added g3log and glog benchmarks. --- .gitmodules | 3 +++ bench/CMakeLists.txt | 10 ++----- bench/g3log-async.cpp | 63 +++++++++++++++++++++++++++++++++++++++++++ vendor/CMakeLists.txt | 5 +++- vendor/g3log | 1 + 5 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 bench/g3log-async.cpp create mode 160000 vendor/g3log diff --git a/.gitmodules b/.gitmodules index 383c487a..0a9050b3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,3 +7,6 @@ [submodule "vendor/easyloggingpp"] path = vendor/easyloggingpp url = https://github.com/easylogging/easyloggingpp.git +[submodule "vendor/g3log"] + path = vendor/g3log + url = https://github.com/KjellKod/g3log.git diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt index 628507ab..563f5b65 100644 --- a/bench/CMakeLists.txt +++ b/bench/CMakeLists.txt @@ -55,19 +55,13 @@ if(Boost_FOUND) add_benchmark(boost-bench-mt LIBS ${Boost_LIBRARIES} INCLUDES ${Boost_INCLUDE_DIRS} DEFINITIONS ${BOOST_DEFS}) endif() -find_package(glog QUIET) if(TARGET glog) add_benchmark(glog-bench LIBS glog) add_benchmark(glog-bench-mt LIBS glog) endif() -# TODO make g2log find script -# TODO use g2log git submodule -find_package(g2log QUIET) -if(g2log-FOUND) - set(G2LOG_LIBRARIES lib_g2logger) - set(G2LOG_INCLUDE_DIRS /home/gabi/devel/g2log/g2log/src) - add_benchmark(g2log-async LIBS ${G2LOG_LIBRARIES} INCLUDES ${G2LOG_INCLUDE_DIRS}) +if(TARGET g3logger) + add_benchmark(g3log-async LIBS g3logger INCLUDES "${g3log_SOURCE_DIR}/src") endif() if(TARGET easylogging) diff --git a/bench/g3log-async.cpp b/bench/g3log-async.cpp new file mode 100644 index 00000000..f1e5c17f --- /dev/null +++ b/bench/g3log-async.cpp @@ -0,0 +1,63 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#include +#include +#include +#include +#include + +#include +#include + +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 g3log = g3::LogWorker::createLogWorker(); + auto defaultHandler = g3log->addDefaultLogger(argv[0], "logs"); + g3::initializeLogging(g3log.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/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index b2abdde4..86b7e33b 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -7,12 +7,15 @@ add_subdirectory(zf_log) -#add_subdirectory(glog) +add_subdirectory(glog) add_library(easylogging INTERFACE) set(SPDLOG_VENDORED_EASYLOGGING_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/easyloggingpp" CACHE INTERNAL "" FORCE) target_include_directories(easylogging INTERFACE "${SPDLOG_VENDORED_EASYLOGGING_ROOT}/src") +add_subdirectory(g3log) + + #add_library(zflog INTERFACE) #set(SPDLOG_VENDORED_ZFLOG_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/zf_log" CACHE INTERNAL "" FORCE) #target_include_directories(zflog INTERFACE "${SPDLOG_VENDORED_ZFLOG_ROOT}/zf_log") diff --git a/vendor/g3log b/vendor/g3log new file mode 160000 index 00000000..6c1698c4 --- /dev/null +++ b/vendor/g3log @@ -0,0 +1 @@ +Subproject commit 6c1698c4f7db6b9e4246ead38051f9866ea3ac06