diff --git a/bench/Makefile b/bench/Makefile index 8fecdf25..91b53faf 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -3,7 +3,7 @@ CXXFLAGS = -march=native -Wall -Wextra -Wshadow -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 +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 spdlog-bench: spdlog-bench.cpp $(CXX) spdlog-bench.cpp -o spdlog-bench $(CXXFLAGS) $(CXX_RELEASE_FLAGS) @@ -34,6 +34,15 @@ glog-bench-mt: glog-bench-mt.cpp $(CXX) glog-bench-mt.cpp -o glog-bench-mt $(CXXFLAGS) $(GLOG_FLAGS) $(CXX_RELEASE_FLAGS) +G2LOG_FLAGS = -I/home/gabi/devel/g2log/g2log/src -L/home/gabi/devel/g2log/g2log -llib_g2logger +g2log-bench: g2log-bench.cpp + $(CXX) g2log-bench.cpp -o g2log-bench $(CXXFLAGS) $(G2LOG_FLAGS) $(CXX_RELEASE_FLAGS) + +g2log-bench-mt: g2log-bench-mt.cpp + $(CXX) g2log-bench-mt.cpp -o g2log-bench-mt $(CXXFLAGS) $(G2LOG_FLAGS) $(CXX_RELEASE_FLAGS) + + + clean: rm -f *.o logs/* spdlog-bench spdlog-bench-mt boost-bench boost-bench-mt glog-bench diff --git a/bench/g2log-bench-mt.cpp b/bench/g2log-bench-mt.cpp new file mode 100644 index 00000000..d8098ad0 --- /dev/null +++ b/bench/g2log-bench-mt.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include + +#include "g2logworker.h" +#include "g2log.h" + +using namespace std; + +int main(int argc, char* argv[]) +{ + + int thread_count = 10; + if(argc > 1) + thread_count = atoi(argv[1]); + + int howmany = 1000000; + + g2LogWorker g2log(argv[0], "logs"); + g2::initializeLogging(&g2log); + + + 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) << "glog message #" << counter << ": This is some text for your pleasure"; + } + })); + } + + + for(auto &t:threads) + { + t.join(); + }; + + + + return 0; +} diff --git a/bench/g2log-bench.cpp b/bench/g2log-bench.cpp new file mode 100644 index 00000000..d06131b8 --- /dev/null +++ b/bench/g2log-bench.cpp @@ -0,0 +1,16 @@ +#include "g2logworker.h" +#include "g2log.h" + + +int main(int, char* argv[]) +{ + int howmany = 1000000; + + g2LogWorker g2log(argv[0], "logs"); + g2::initializeLogging(&g2log); + + for(int i = 0 ; i < howmany; ++i) + LOG(INFO) << "g2log message # " << i << ": This is some text for your pleasure"; + + return 0; +} diff --git a/bench/run_all.bat b/bench/run_all.bat deleted file mode 100644 index 0cfffa28..00000000 --- a/bench/run_all.bat +++ /dev/null @@ -1,28 +0,0 @@ -@echo off -echo Running benchmarks (all with 1000,000 writes to the logs folder) -echo ================================== -echo boost-bench (single thread) -echo %time% -.\boost-bench -echo %time% -echo ================================== -choice /n /c y /d y /t 1 >NUL -echo spdlog-bench (single thread) -echo %time% -.\spdlog-bench -echo %time% -echo ================================== -choice /n /c y /d y /t 1 >NUL -echo boost-bench-mt (10 threads, single logger) -echo %time% -.\boost-bench-mt -echo %time% -echo ================================== -choice /n /c y /d y /t 1 >NUL -echo spdlog-bench-mt (10 threads, single logger) -echo %time% -.\spdlog-bench-mt -echo %time% -echo ================================== - - diff --git a/bench/run_all.sh b/bench/run_all.sh index c37b56f8..9f76d584 100755 --- a/bench/run_all.sh +++ b/bench/run_all.sh @@ -6,31 +6,49 @@ time ./boost-bench echo echo sleep 3 + echo "glog-bench (single thread).." time ./glog-bench echo echo sleep 3 + +echo "g2log-bench (single thread).." +time ./g2log-bench +echo +echo +sleep 3 + echo "spdlog-bench (single thread)" time ./spdlog-bench echo echo sleep 3 + echo "boost-bench-mt (10 threads, single logger)".. time ./boost-bench-mt echo echo sleep 3 + echo "glog-bench-mt (10 threads, single logger)".. time ./glog-bench-mt echo echo sleep 3 + +echo "g2log-bench-mt (10 threads, single logger)".. +time ./g2log-bench-mt +echo +echo +sleep 3 + echo "spdlog-bench-mt (10 threads, single logger)".. time ./spdlog-bench-mt echo echo sleep 3 + echo "spdlog-bench-mt-async (10 threads, single logger)".. time ./spdlog-bench-mt-async