diff --git a/bench/Makefile b/bench/Makefile index a31868a6..1a510c8e 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 boost-bench boost-bench-mt +all: spdlog-bench spdlog-bench-mt 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) @@ -20,8 +20,16 @@ boost-bench-mt: boost-bench-mt.cpp $(CXX) boost-bench-mt.cpp -o boost-bench-mt $(CXXFLAGS) $(BOOST_FLAGS) $(CXX_RELEASE_FLAGS) +GLOG_FLAGS = -lglog +glog-bench: glog-bench.cpp + $(CXX) glog-bench.cpp -o glog-bench $(CXXFLAGS) $(GLOG_FLAGS) $(CXX_RELEASE_FLAGS) + +glog-bench-mt: glog-bench-mt.cpp + $(CXX) glog-bench-mt.cpp -o glog-bench-mt $(CXXFLAGS) $(GLOG_FLAGS) $(CXX_RELEASE_FLAGS) + + clean: - rm -f *.o logs/*.txt spdlog-bench spdlog-bench-mt boost-bench boost-bench-mt + rm -f *.o logs/*.txt spdlog-bench spdlog-bench-mt boost-bench boost-bench-mt glog-bench rebuild: clean all diff --git a/bench/glog-bench-mt.cpp b/bench/glog-bench-mt.cpp new file mode 100644 index 00000000..d681b535 --- /dev/null +++ b/bench/glog-bench-mt.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +#include "glog/logging.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; + + FLAGS_logtostderr = 0; + FLAGS_log_dir = "logs"; + google::InitGoogleLogging(argv[0]); + + 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; + } + })); + } + + + for(auto &t:threads) + { + t.join(); + }; + + + + return 0; +} diff --git a/bench/glog-bench.cpp b/bench/glog-bench.cpp new file mode 100644 index 00000000..8158df64 --- /dev/null +++ b/bench/glog-bench.cpp @@ -0,0 +1,17 @@ + +#include "glog/logging.h" + + +int main(int, char* argv[]) +{ + int howmany = 1000000; + + + FLAGS_logtostderr = 0; + FLAGS_log_dir = "logs"; + google::InitGoogleLogging(argv[0]); + for(int i = 0 ; i < howmany; ++i) + LOG(INFO) << "glog message # " << i; + + return 0; +} diff --git a/bench/run_all.sh b/bench/run_all.sh index 1d2dad84..cdef0de4 100755 --- a/bench/run_all.sh +++ b/bench/run_all.sh @@ -4,19 +4,26 @@ echo echo "boost-bench (single thread).." time ./boost-bench echo ================================== -sleep 1 +sleep 3 +echo "glog-bench (single thread).." +time ./glog-bench +echo ================================== +sleep 3 echo "spdlog-bench (single thread)" time ./spdlog-bench echo ================================== -sleep 1 +sleep 3 echo "boost-bench-mt (10 threads, single logger)".. time ./boost-bench-mt echo ================================== -sleep 1 +sleep 3 +echo "glog-bench-mt (10 threads, single logger)".. +time ./glog-bench-mt +echo ================================== +sleep 3 echo "spdlog-bench-mt (10 threads, single logger)".. time ./spdlog-bench-mt echo ================================== -sleep 1 echo diff --git a/bench/spdlog-bench.cpp b/bench/spdlog-bench.cpp index ce739547..bfcc1dc6 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_mt("file_logger", "logs/spd-sample", 100 *1024 * 1024 , 5); logger->set_pattern("[%Y-%b-%d %T.%e]: %v"); for(int i = 0 ; i < howmany; ++i) diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index cc995cd4..6d46e940 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -130,7 +130,7 @@ inline int fopen_s(FILE** fp, const std::string& filename, const char* mode) } //Return utc offset in minutes or -1 on failure -inline int utc_minutes_offset(const std::tm& tm = localtime()) +inline int utc_minutes_offset(const std::tm& tm = details::os::localtime()) { #ifdef _WIN32