From b38a36451d45885ef0ea4ad9044207d6e6f6d32b Mon Sep 17 00:00:00 2001 From: gabime Date: Sat, 20 Dec 2014 18:57:01 +0200 Subject: [PATCH] easylogging bench --- bench/Makefile | 15 +++++++++-- bench/easyl.conf | 10 ++++++++ bench/easylogging-bench-mt.cpp | 47 ++++++++++++++++++++++++++++++++++ bench/easylogging-bench.cpp | 16 ++++++++++++ bench/run_all.sh | 4 +++ 5 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 bench/easyl.conf create mode 100644 bench/easylogging-bench-mt.cpp create mode 100644 bench/easylogging-bench.cpp diff --git a/bench/Makefile b/bench/Makefile index 6a1e93ca..f1bb6790 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -3,7 +3,9 @@ CXXFLAGS = -march=native -Wall -Wshadow -Wextra -pedantic -std=c++11 -pthread -W CXX_RELEASE_FLAGS = -O3 -flto -all: spdlog-bench spdlog-bench-mt spdlog-bench-async spdlog-bench-mt-async boost-bench boost-bench-mt glog-bench glog-bench-mt g2log-bench g2log-bench-mt +binaries=spdlog-bench spdlog-bench-mt spdlog-bench-async spdlog-bench-mt-async boost-bench boost-bench-mt glog-bench glog-bench-mt g2log-bench g2log-bench-mt easylogging-bench easylogging-bench-mt + +all: $(binaries) spdlog-bench: spdlog-bench.cpp $(CXX) spdlog-bench.cpp -o spdlog-bench $(CXXFLAGS) $(CXX_RELEASE_FLAGS) @@ -43,8 +45,17 @@ g2log-bench-mt: g2log-bench-mt.cpp + +EASYL_FLAGS = -I../../easylogging/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) + +.PHONY: clean + clean: - rm -f *.o logs/* spdlog-bench spdlog-bench-mt spdlog-bench-async spdlog-bench-mt-async boost-bench boost-bench-mt glog-bench glog-bench-mt g2log-bench g2log-bench-mt + rm -f *.o logs/* $(binaries) rebuild: clean all diff --git a/bench/easyl.conf b/bench/easyl.conf new file mode 100644 index 00000000..02f14989 --- /dev/null +++ b/bench/easyl.conf @@ -0,0 +1,10 @@ +* GLOBAL: + FORMAT = "[%datetime]: %msg" + FILENAME = ./logs/easylogging.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/easylogging-bench-mt.cpp b/bench/easylogging-bench-mt.cpp new file mode 100644 index 00000000..edea2103 --- /dev/null +++ b/bench/easylogging-bench-mt.cpp @@ -0,0 +1,47 @@ +#include +#include +#include + +#define _ELPP_THREAD_SAFE +#include "easylogging++.h" +_INITIALIZE_EASYLOGGINGPP + +using namespace std; + +int main(int argc, char* argv[]) +{ + + int thread_count = 10; + if(argc > 1) + thread_count = atoi(argv[1]); + + int howmany = 1000000; + + // Load configuration from file + el::Configurations conf("easyl.conf"); + el::Loggers::reconfigureLogger("default", conf); + + std::atomic msg_counter {0}; + vector threads; + + 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(); + }; + + return 0; +} diff --git a/bench/easylogging-bench.cpp b/bench/easylogging-bench.cpp new file mode 100644 index 00000000..1a4e11ab --- /dev/null +++ b/bench/easylogging-bench.cpp @@ -0,0 +1,16 @@ +#include "easylogging++.h" + +_INITIALIZE_EASYLOGGINGPP + +int main(int, char* []) +{ + int howmany = 1000000; + + // Load configuration from file + el::Configurations conf("easyl.conf"); + el::Loggers::reconfigureLogger("default", conf); + + for(int i = 0 ; i < howmany; ++i) + LOG(INFO) << "easylog message #" << i << ": This is some text for your pleasure"; + return 0; +} diff --git a/bench/run_all.sh b/bench/run_all.sh index 4e0eb531..6b6cc74c 100755 --- a/bench/run_all.sh +++ b/bench/run_all.sh @@ -1,4 +1,8 @@ #~/bin/bash + +exec 2>&1 + + echo "Running benchmakrs (all with 1000,000 writes to the logs folder)" echo echo "boost-bench (single thread).."