spdlog vs boost benchmarks
This commit is contained in:
		
							
								
								
									
										31
									
								
								bench-comparison/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								bench-comparison/Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					CXX	= g++
 | 
				
			||||||
 | 
					CXXFLAGS	= -march=native -Wall  -pthread  -I../include --std=c++11
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CXX_RELEASE_FLAGS = -O3 -flto
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					all:	spdlog-bench spdlog-bench-mt boost-bench boost-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)	
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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	
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					boost-bench: boost-bench.cpp
 | 
				
			||||||
 | 
						$(CXX) boost-bench.cpp -o boost-bench $(CXXFLAGS) $(BOOST_FLAGS) $(CXX_RELEASE_FLAGS)
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					boost-bench-mt: boost-bench-mt.cpp
 | 
				
			||||||
 | 
						$(CXX) boost-bench-mt.cpp -o boost-bench-mt $(CXXFLAGS) $(BOOST_FLAGS) $(CXX_RELEASE_FLAGS)	
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					clean:
 | 
				
			||||||
 | 
						rm -f *.o logs/*.txt spdlog-bench spdlog-bench-mt boost-bench boost-bench-mt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rebuild: clean all
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										76
									
								
								bench-comparison/boost-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								bench-comparison/boost-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,76 @@
 | 
				
			|||||||
 | 
					#include <thread>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					#include <atomic>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <boost/log/core.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/trivial.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/expressions.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/sinks/text_file_backend.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/utility/setup/file.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/utility/setup/common_attributes.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/sources/severity_logger.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/sources/record_ostream.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace logging = boost::log;
 | 
				
			||||||
 | 
					namespace src = boost::log::sources;
 | 
				
			||||||
 | 
					namespace sinks = boost::log::sinks;
 | 
				
			||||||
 | 
					namespace keywords = boost::log::keywords;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void init()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    logging::add_file_log
 | 
				
			||||||
 | 
					    (
 | 
				
			||||||
 | 
					        keywords::file_name = "logs/boost-sample_%N.log",                              /*< file name pattern >*/
 | 
				
			||||||
 | 
					        keywords::rotation_size = 10 * 1024 * 1024,                                   /*< rotate files every 10 MiB... >*/
 | 
				
			||||||
 | 
					        keywords::auto_flush = false,
 | 
				
			||||||
 | 
					        keywords::format = "[%TimeStamp%]: %Message%"                                 
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    logging::core::get()->set_filter
 | 
				
			||||||
 | 
					    (
 | 
				
			||||||
 | 
					        logging::trivial::severity >= logging::trivial::info
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int, char*[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int thread_count = 10;
 | 
				
			||||||
 | 
						int howmany = 1000000;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					    init();
 | 
				
			||||||
 | 
					    logging::add_common_attributes();
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    using namespace logging::trivial;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    src::severity_logger_mt< severity_level > lg;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    std::atomic<int > msg_counter {0};
 | 
				
			||||||
 | 
					    vector<thread> threads;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    for (int t = 0; t < thread_count; ++t)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        threads.push_back(std::thread([&]()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            while (true)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                int counter = ++msg_counter;
 | 
				
			||||||
 | 
					                if (counter > howmany) break;
 | 
				
			||||||
 | 
					              BOOST_LOG_SEV(lg, info) << "Boost logger message #" << counter;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for(auto &t:threads)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        t.join();
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										44
									
								
								bench-comparison/boost-bench.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								bench-comparison/boost-bench.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					#include <boost/log/core.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/trivial.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/expressions.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/sinks/text_file_backend.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/utility/setup/file.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/utility/setup/common_attributes.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/sources/severity_logger.hpp>
 | 
				
			||||||
 | 
					#include <boost/log/sources/record_ostream.hpp>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace logging = boost::log;
 | 
				
			||||||
 | 
					namespace src = boost::log::sources;
 | 
				
			||||||
 | 
					namespace sinks = boost::log::sinks;
 | 
				
			||||||
 | 
					namespace keywords = boost::log::keywords;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void init()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    logging::add_file_log
 | 
				
			||||||
 | 
					    (
 | 
				
			||||||
 | 
					        keywords::file_name = "logs/boost-sample_%N.log",                              /*< file name pattern >*/
 | 
				
			||||||
 | 
					        keywords::rotation_size = 10 * 1024 * 1024,                                   /*< rotate files every 10 MiB... >*/
 | 
				
			||||||
 | 
					        keywords::auto_flush = false,
 | 
				
			||||||
 | 
					        keywords::format = "[%TimeStamp%]: %Message%"                                 
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    logging::core::get()->set_filter
 | 
				
			||||||
 | 
					    (
 | 
				
			||||||
 | 
					        logging::trivial::severity >= logging::trivial::info
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int, char*[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    init();
 | 
				
			||||||
 | 
					    logging::add_common_attributes();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    using namespace logging::trivial;
 | 
				
			||||||
 | 
					    src::severity_logger_mt< severity_level > lg;
 | 
				
			||||||
 | 
						for(int i  = 0 ; i < 1000000; ++i)
 | 
				
			||||||
 | 
						    BOOST_LOG_SEV(lg, info) << "Boost logger message #" << i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										4
									
								
								bench-comparison/logs/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								bench-comparison/logs/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					# Ignore everything in this directory
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					# Except this file
 | 
				
			||||||
 | 
					!.gitignore
 | 
				
			||||||
							
								
								
									
										46
									
								
								bench-comparison/spdlog-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								bench-comparison/spdlog-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					#include <thread>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
 | 
					#include <atomic>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "spdlog/spdlog.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					using namespace std;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					int main(int, char*[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int thread_count = 10;
 | 
				
			||||||
 | 
						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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						logger->set_pattern("[%Y-%b-%d %T.%e]: %v");
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						std::atomic<int > msg_counter {0};
 | 
				
			||||||
 | 
					    vector<thread> 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 logger message #" << counter;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    for(auto &t:threads)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        t.join();
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										16
									
								
								bench-comparison/spdlog-bench.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								bench-comparison/spdlog-bench.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					#include "spdlog/spdlog.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int main(int, char*[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						logger->set_pattern("[%Y-%b-%d %T.%e]: %v");
 | 
				
			||||||
 | 
						for(int i  = 0 ; i < 1000000; ++i)
 | 
				
			||||||
 | 
						    logger->info() << "spdlogger message #" << i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user