easylogging bench and fix async compare with g2log

This commit is contained in:
gabime 2014-12-20 22:25:55 +02:00
parent 37a14f0d22
commit 4250796aea
9 changed files with 126 additions and 145 deletions

View File

@ -35,10 +35,22 @@ Just copy the files to your build tree and use a C++11 compiler
Below are some [benchmarks](bench) comparing the time needed to log 1,000,000 lines to file under Ubuntu 64 bit, Intel i7-4770 CPU @ 3.40GHz (the best of 3 runs for each logger):
|threads|boost log|glog|g2log <sup>async mode</sup>|spdlog|spdlog <sup>async mode</sup>|
|-------|:-------:|:-----:|------:|------:|------:|
|1|4.779s|1.109s|3.155s|0.319s|0.212s
|10|15.151ss|3.546s|3.500s|0.641s|0.199s|
### Synchronous mode
|threads|boost log|glog |easylogging |spdlog|
|-------|:-------:|:-----:|----------:|------:|
|1| 4.169s |1.066s |0.975s :|0.302s|
|10| 16.029 |3.032s |2.857 :|0.968s|
|100| 15.008 |1.139s |4.512s :|0.497s|
### ASynchronous mode
|threads|g2log |spdlog<sup>async mode</sup>|
|:-------|----- :|:-------------------------:|
|1| 1.850s |0.216s
|10| 0.943s |0.173s
|100| 0.959s |0.202
## Usage Example

View File

@ -3,7 +3,7 @@ CXXFLAGS = -march=native -Wall -Wextra -pedantic -std=c++11 -pthread -Wl,--no-as
CXX_RELEASE_FLAGS = -O3 -flto
binaries=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 easylogging-bench easylogging-bench-mt
binaries=spdlog-bench spdlog-bench-mt spdlog-async boost-bench boost-bench-mt glog-bench glog-bench-mt g2log-async easylogging-bench easylogging-bench-mt
all: $(binaries)
@ -13,11 +13,9 @@ spdlog-bench: spdlog-bench.cpp
spdlog-bench-mt: spdlog-bench-mt.cpp
$(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-async: spdlog-async.cpp
$(CXX) spdlog-async.cpp -o spdlog-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
@ -37,11 +35,8 @@ glog-bench-mt: glog-bench-mt.cpp
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)
g2log-async: g2log-async.cpp
$(CXX) g2log-async.cpp -o g2log-async $(CXXFLAGS) $(G2LOG_FLAGS) $(CXX_RELEASE_FLAGS)

View File

@ -2,19 +2,22 @@
#include <vector>
#include <atomic>
#include <iostream>
#include <chrono>
#include "g2logworker.h"
#include "g2log.h"
using namespace std;
template<typename T> std::string format(const T& value);
int main(int argc, char* argv[])
{
using namespace std::chrono;
using clock=steady_clock;
int thread_count = 10;
if(argc > 1)
thread_count = atoi(argv[1]);
int howmany = 1000000;
g2LogWorker g2log(argv[0], "logs");
@ -23,7 +26,7 @@ int main(int argc, char* argv[])
std::atomic<int > msg_counter {0};
vector<thread> threads;
auto start = clock::now();
for (int t = 0; t < thread_count; ++t)
{
threads.push_back(std::thread([&]()
@ -43,7 +46,12 @@ int main(int argc, char* argv[])
t.join();
};
duration<float> delta = clock::now() - start;
float deltaf = delta.count();
auto rate = howmany/deltaf;
return 0;
cout << "Total: " << howmany << std::endl;
cout << "Threads: " << thread_count << std::endl;
std::cout << "Delta = " << deltaf << " seconds" << std::endl;
std::cout << "Rate = " << rate << "/sec" << std::endl;
}

View File

@ -1,16 +0,0 @@
#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;
}

View File

@ -41,7 +41,5 @@ int main(int argc, char* argv[])
t.join();
};
return 0;
}

View File

@ -1,81 +1,80 @@
#~/bin/bash
#execute each bench 3 times and print the timing
exec 2>&1
#execute and time given exe 3 times
bench_exe ()
{
echo "**************** $1 ****************"
for i in {1..3}; do
time ./$1 $2;
rm -f logs/*
sleep 3
done;
}
echo "Running benchmakrs (all with 1000,000 writes to the logs folder)"
echo
echo "boost-bench (single thread).."
for i in {1..3}; do time ./boost-bench; done
rm -f logs/*
echo
echo
sleep 5
#execute given async tests 3 times (timing is already builtin)
bench_async ()
{
echo "**************** $1 ****************"
for i in {1..3}; do
./$1 $2;
rm -f logs/*
sleep 3
done;
}
echo "glog-bench (single thread).."
for i in {1..3}; do time ./glog-bench; done
rm -f logs/*
echo
echo
sleep 5
echo "g2log-bench (single thread).."
for i in {1..3}; do time ./g2log-bench; done
rm -f logs/*
echo
echo
sleep 5
echo "----------------------------------------------------------"
echo "Single threaded benchmarks.. (1 thread, 1,000,000 lines)"
echo "----------------------------------------------------------"
for exe in boost-bench glog-bench easylogging-bench spdlog-bench;
do
bench_exe $exe 1
done;
echo "spdlog-bench (single thread)"
for i in {1..3}; do time ./spdlog-bench; done
rm -f logs/*
echo
echo
sleep 5
echo "------------------------------------"
echo "Multithreaded benchmarks.."
echo "------------------------------------"
echo "boost-bench-mt (10 threads, single logger)"..
for i in {1..3}; do ./boost-bench-mt; done
rm -f logs/*
echo
echo
sleep 5
echo "----------------------------------------------------------"
echo "Multi threaded benchmarks.. (10 threads, 1,000,000 lines)"
echo "----------------------------------------------------------"
for exe in boost-bench-mt glog-bench-mt easylogging-bench-mt spdlog-bench-mt;
do
bench_exe $exe 10
done;
echo "glog-bench-mt (10 threads, single logger)"..
for i in {1..3}; do time ./glog-bench-mt; done
rm -f logs/*
echo
echo
sleep 5
echo "----------------------------------------------------------"
echo "Multi threaded benchmarks.. (100 threads, 1,000,000 lines)"
echo "----------------------------------------------------------"
for exe in boost-bench-mt glog-bench-mt easylogging-bench-mt spdlog-bench-mt;
do
bench_exe $exe 100
done;
echo "g2log-bench-mt (10 threads, single logger)"..
for i in {1..3}; do time ./g2log-bench-mt; done
rm -f logs/*
echo
echo
sleep 5
echo "spdlog-bench-mt (10 threads, single logger)"..
for i in {1..3}; do time ./spdlog-bench-mt; done
rm -f logs/*
echo
echo
sleep 5
echo "---------------------------------------------------------------"
echo "Async, single threaded benchmark.. (1 thread, 1,000,000 lines)"
echo "---------------------------------------------------------------"
for exe in spdlog-async g2log-async
do
bench_async $exe 1
done;
echo "------------------------------------"
echo "Async benchmarks.."
echo "------------------------------------"
echo "---------------------------------------------------------------"
echo "Async, multi threaded benchmark.. (10 threads, 1,000,000 lines)"
echo "---------------------------------------------------------------"
for exe in spdlog-async g2log-async
do
bench_async $exe 10
done;
echo "spdlog-bench-async (single thread)"..
for i in {1..3}; do time ./spdlog-bench-async; done
rm -f logs/*
echo
echo
sleep 5
echo "spdlog-bench-mt-async (10 threads, single logger)"..
for i in {1..3}; do time ./spdlog-bench-mt-async; done
echo "---------------------------------------------------------------"
echo "Async, multi threaded benchmark.. (100 threads, 1,000,000 lines)"
echo "---------------------------------------------------------------"
for exe in spdlog-async g2log-async
do
bench_async $exe 100
done;

View File

@ -1,31 +1,34 @@
#include <thread>
#include <vector>
#include <atomic>
#include <iostream>
#include <chrono>
#include "spdlog/spdlog.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
using namespace std::chrono;
using clock=steady_clock;
namespace spd = spdlog;
int thread_count = 10;
if(argc > 1)
thread_count = atoi(argv[1]);
int howmany = 1000000;
int howmany = 1048576;
namespace spd = spdlog;
spd::set_async_mode(howmany);
///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);
spd::set_async_mode(1048576);
auto logger = spdlog::create<spd::sinks::simple_file_sink_mt>("file_logger", "logs/spd-bench-async.txt", false);
logger->set_pattern("[%Y-%b-%d %T.%e]: %v");
std::atomic<int > msg_counter {0};
vector<thread> threads;
auto start = clock::now();
for (int t = 0; t < thread_count; ++t)
{
threads.push_back(std::thread([&]()
@ -39,13 +42,17 @@ int main(int argc, char* argv[])
}));
}
for(auto &t:threads)
{
t.join();
};
//because spdlog async logger waits for the back thread logger to finish all messages upon destrcuting,
//and we want to measure only the time it took to push those messages to the backthread..
abort();
duration<float> delta = clock::now() - start;
float deltaf = delta.count();
auto rate = howmany/deltaf;
cout << "Total: " << howmany << std::endl;
cout << "Threads: " << thread_count << std::endl;
std::cout << "Delta = " << deltaf << " seconds" << std::endl;
std::cout << "Rate = " << rate << "/sec" << std::endl;
}

View File

@ -1,22 +0,0 @@
#include "spdlog/spdlog.h"
int main(int, char* [])
{
int howmany = 1048576;
namespace spd = spdlog;
spd::set_async_mode(howmany);
///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";
//because spdlog async logger waits for the back thread logger to finish all messages upon destrcuting,
//and we want to measure only the time it took to push those messages to the backthread..
abort();
return 0;
}

View File

@ -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_st("file_logger", "logs/spd-sample", 10 *1024 * 1024 , 5);
auto logger = spdlog::create<spd::sinks::simple_file_sink_st>("file_logger", "logs/spd-bench-st.txt", false);
logger->set_pattern("[%Y-%b-%d %T.%e]: %v");
for(int i = 0 ; i < howmany; ++i)