mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-24 17:41:34 +08:00
glog bench
This commit is contained in:
parent
ece27ac952
commit
6f550c3271
@ -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
|
||||
|
48
bench/glog-bench-mt.cpp
Normal file
48
bench/glog-bench-mt.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <iostream>
|
||||
|
||||
#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<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;
|
||||
LOG(INFO) << "glog message # " << counter;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
for(auto &t:threads)
|
||||
{
|
||||
t.join();
|
||||
};
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
17
bench/glog-bench.cpp
Normal file
17
bench/glog-bench.cpp
Normal file
@ -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;
|
||||
}
|
@ -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
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user