diff --git a/bench/Makefile b/bench/Makefile index 3b9e7e73..8fecdf25 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -3,13 +3,19 @@ CXXFLAGS = -march=native -Wall -Wextra -Wshadow -pedantic -std=c++11 -pthread -W CXX_RELEASE_FLAGS = -O3 -flto -all: spdlog-bench spdlog-bench-mt 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 spdlog-bench: spdlog-bench.cpp $(CXX) spdlog-bench.cpp -o spdlog-bench $(CXXFLAGS) $(CXX_RELEASE_FLAGS) spdlog-bench-mt: spdlog-bench-mt.cpp - $(CXX) spdlog-bench-mt.cpp -o spdlog-bench-mt $(CXXFLAGS) $(CXX_RELEASE_FLAGS) + $(CXX) spdlog-bench-mt.cpp -o spdlog-bench-mt $(CXXFLAGS) $(CXX_RELEASE_FLAGS) + +spdlog-bench-async: spdlog-bench-async.cpp + $(CXX) spdlog-bench-async.cpp -o spdlog-bench-async $(CXXFLAGS) $(CXX_RELEASE_FLAGS) + +spdlog-bench-mt-async: spdlog-bench-mt-async.cpp + $(CXX) spdlog-bench-mt-async.cpp -o spdlog-bench-mt-async $(CXXFLAGS) $(CXX_RELEASE_FLAGS) BOOST_FLAGS = -DBOOST_LOG_DYN_LINK -I/home/gabi/devel/boost_1_56_0/ -L/home/gabi/devel/boost_1_56_0/stage/lib -lboost_log -lboost_log_setup -lboost_filesystem -lboost_system -lboost_thread -lboost_regex -lboost_date_time -lboost_chrono diff --git a/bench/run_all.sh b/bench/run_all.sh index cdef0de4..c37b56f8 100755 --- a/bench/run_all.sh +++ b/bench/run_all.sh @@ -3,27 +3,36 @@ echo "Running benchmakrs (all with 1000,000 writes to the logs folder" echo echo "boost-bench (single thread).." time ./boost-bench -echo ================================== +echo +echo sleep 3 echo "glog-bench (single thread).." time ./glog-bench -echo ================================== +echo +echo sleep 3 echo "spdlog-bench (single thread)" time ./spdlog-bench -echo ================================== +echo +echo sleep 3 echo "boost-bench-mt (10 threads, single logger)".. time ./boost-bench-mt -echo ================================== +echo +echo sleep 3 echo "glog-bench-mt (10 threads, single logger)".. time ./glog-bench-mt -echo ================================== +echo +echo sleep 3 echo "spdlog-bench-mt (10 threads, single logger)".. time ./spdlog-bench-mt -echo ================================== echo +echo +sleep 3 +echo "spdlog-bench-mt-async (10 threads, single logger)".. +time ./spdlog-bench-mt-async + diff --git a/bench/spdlog-bench-async.cpp b/bench/spdlog-bench-async.cpp new file mode 100644 index 00000000..a7c7e97c --- /dev/null +++ b/bench/spdlog-bench-async.cpp @@ -0,0 +1,18 @@ + +#include "spdlog/spdlog.h" + + +int main(int, char* []) +{ + int howmany = 1000000; + namespace spd = spdlog; + spd::set_async_mode(howmany, std::chrono::seconds(0)); + ///Create a file rotating logger with 5mb size max and 3 rotated files + auto logger = spd::rotating_logger_mt("file_logger", "logs/spd-sample", 10 *1024 * 1024 , 5); + + logger->set_pattern("[%Y-%b-%d %T.%e]: %v"); + for(int i = 0 ; i < howmany; ++i) + logger->info() << "spdlog message #" << i << ": This is some text for your pleasure"; + spd::stop(); + return 0; +} diff --git a/bench/spdlog-bench-mt-async.cpp b/bench/spdlog-bench-mt-async.cpp new file mode 100644 index 00000000..98ac371c --- /dev/null +++ b/bench/spdlog-bench-mt-async.cpp @@ -0,0 +1,50 @@ +#include +#include +#include + +#include "spdlog/spdlog.h" + +#include +using namespace std; + +int main(int argc, char* argv[]) +{ + + int thread_count = 10; + if(argc > 1) + thread_count = atoi(argv[1]); + + int howmany = 1000000; + + namespace spd = spdlog; + spd::set_async_mode(howmany, std::chrono::seconds(0)); + ///Create a file rotating logger with 5mb size max and 3 rotated files + auto logger = spd::rotating_logger_mt("file_logger", "logs/spd-sample", 10 *1024 * 1024 , 5); + + logger->set_pattern("[%Y-%b-%d %T.%e]: %v"); + + 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; + logger->info() << "spdlog message #" << counter << ": This is some text for your pleasure"; + } + })); + } + + + for(auto &t:threads) + { + t.join(); + }; + + spd::stop(); + return 0; +} diff --git a/bench/spdlog-bench.cpp b/bench/spdlog-bench.cpp index 1d0fc0df..8c28dac5 100644 --- a/bench/spdlog-bench.cpp +++ b/bench/spdlog-bench.cpp @@ -7,7 +7,7 @@ int main(int, char* []) int howmany = 1000000; namespace spd = spdlog; ///Create a file rotating logger with 5mb size max and 3 rotated files - auto logger = spd::rotating_logger_mt("file_logger", "logs/spd-sample", 10 *1024 * 1024 , 5); + auto logger = spd::rotating_logger_st("file_logger", "logs/spd-sample", 10 *1024 * 1024 , 5); logger->set_pattern("[%Y-%b-%d %T.%e]: %v"); for(int i = 0 ; i < howmany; ++i)