mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-24 17:41:34 +08:00
Added async to benchmarks
This commit is contained in:
parent
c56fae39e8
commit
0926a6e2c3
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
||||
|
18
bench/spdlog-bench-async.cpp
Normal file
18
bench/spdlog-bench-async.cpp
Normal file
@ -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;
|
||||
}
|
50
bench/spdlog-bench-mt-async.cpp
Normal file
50
bench/spdlog-bench-mt-async.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;
|
||||
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<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 message #" << counter << ": This is some text for your pleasure";
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
for(auto &t:threads)
|
||||
{
|
||||
t.join();
|
||||
};
|
||||
|
||||
spd::stop();
|
||||
return 0;
|
||||
}
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user