Merge branch 'master' of https://github.com/gabime/spdlog
This commit is contained in:
		
							
								
								
									
										30
									
								
								bench/Makefile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								bench/Makefile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,30 @@
 | 
			
		||||
CXX	= g++
 | 
			
		||||
CXXFLAGS	= -march=native -Wall -Wextra -Wshadow -pedantic -std=c++11 -pthread -Wl,--no-as-needed  -I../include 
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										80
									
								
								bench/boost-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								bench/boost-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,80 @@
 | 
			
		||||
#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 argc, char* argv[])
 | 
			
		||||
{
 | 
			
		||||
    int thread_count = 10;
 | 
			
		||||
    if(argc > 1)
 | 
			
		||||
        thread_count = atoi(argv[1]);
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										45
									
								
								bench/boost-bench.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								bench/boost-bench.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,45 @@
 | 
			
		||||
 | 
			
		||||
#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 argc, char* [])
 | 
			
		||||
{
 | 
			
		||||
    int howmany = 1000000;
 | 
			
		||||
    init();
 | 
			
		||||
    logging::add_common_attributes();
 | 
			
		||||
 | 
			
		||||
    using namespace logging::trivial;
 | 
			
		||||
    src::severity_logger_mt< severity_level > lg;
 | 
			
		||||
    for(int i  = 0 ; i < howmany; ++i)
 | 
			
		||||
        BOOST_LOG_SEV(lg, info) << "Boost logger message #" << i;
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										4
									
								
								bench/logs/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								bench/logs/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
# Ignore everything in this directory
 | 
			
		||||
*
 | 
			
		||||
# Except this file
 | 
			
		||||
!.gitignore
 | 
			
		||||
							
								
								
									
										22
									
								
								bench/run_all.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										22
									
								
								bench/run_all.sh
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
#~/bin/bash
 | 
			
		||||
echo "Running benchmakrs (all with 1000,000 writes to the logs folder"
 | 
			
		||||
echo
 | 
			
		||||
echo "boost-bench (single thread).."
 | 
			
		||||
time ./boost-bench
 | 
			
		||||
echo ==================================
 | 
			
		||||
sleep 1
 | 
			
		||||
echo "spdlog-bench (single thread)"
 | 
			
		||||
time ./spdlog-bench
 | 
			
		||||
echo ==================================
 | 
			
		||||
sleep 1
 | 
			
		||||
echo "boost-bench-mt (10 threads, single logger)"..
 | 
			
		||||
time ./boost-bench-mt
 | 
			
		||||
echo ==================================
 | 
			
		||||
sleep 1
 | 
			
		||||
echo "spdlog-bench-mt (10 threads, single logger)"..
 | 
			
		||||
time ./spdlog-bench-mt
 | 
			
		||||
echo ==================================
 | 
			
		||||
sleep 1
 | 
			
		||||
echo
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										50
									
								
								bench/spdlog-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								bench/spdlog-bench-mt.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,50 @@
 | 
			
		||||
#include <thread>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <atomic>
 | 
			
		||||
 | 
			
		||||
#include "spdlog/spdlog.h"
 | 
			
		||||
 | 
			
		||||
#include <iostream>
 | 
			
		||||
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;
 | 
			
		||||
    ///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;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										17
									
								
								bench/spdlog-bench.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								bench/spdlog-bench.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
 | 
			
		||||
#include "spdlog/spdlog.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int main(int argc, 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);
 | 
			
		||||
 | 
			
		||||
    logger->set_pattern("[%Y-%b-%d %T.%e]: %v");
 | 
			
		||||
    for(int i  = 0 ; i < howmany; ++i)
 | 
			
		||||
        logger->info() << "spdlogger message #" << i;
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user