I recently switched from Boost Log to Spdlog for the purported speed advantages.
However, when I compared the runtimes before and after the switch, I'm finding that Boost Log is significantly faster. I'm wondering if I'm doing something wrong with spdlog that is causing the slowdown or if Boost::Log really is the faster solution.
My application is single threaded, compiled with -O3 and -flto, and I'm using Boost 1.69.0 and Spdlog 1.3.1. My runtimes with Boost::Log is about 37s, with Spdlog its 1m22s, and with Spdlog-async its 2m22. My log entries are usually about 80 characters long made with json using nlohmann/json library (which I know isn't the fastest), and I have 3 different loggers that each target their own file.
Boost Setup:
#include <boost/log/common.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/async_frontend.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/parameter/keyword.hpp>
auto backend = boost::make_shared<sinks::text_file_backend>(keywords::file_name = logfile);
backend->auto_flush(true);
auto sink = boost::make_shared<sinks::asynchronous_sink<sinks::text_file_backend>>(backend);
sink->set_filter(expressions::attr<std::string>("Channel") == "logger_name);
boost::log::core::get()->add_sink(sink);
Elsewhere in the code, I declare a logger
boost::log::sources::channel_logger<> logger(boost::log::keywords::channel = "logger_name");
BOOST_LOG(logger) << "some json string";
Spdlog Setup:
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
auto file_logger = spdlog::basic_logger_st("logger_name", "filename", true);
//I've tried an async logger, but it is even slower!
// auto file_logger = spdlog::basic_logger_st<spdlog::async_factory>("logger_name", "filename", true);
file_logger->set_pattern("%v");
And to use:
std::shared_ptr<spdlog::logger> logger(spdlog::get("logger_name"));
logger->info("some json string");
Any advice would be appreciated.
EDIT
I was able to improve the performance somewhat by adding
spdlog::init_thread_pool(1024*1024, 4);
before creating any asynchronous loggers, but the performance is still about half of Boost Log.