Commit c5afdbdd authored by gabi's avatar gabi

Use fmt::pad for faster formatting of the default format pattern

parent 45628c8e
......@@ -371,18 +371,32 @@ class full_formatter :public flag_formatter
{
auto duration = msg.time.time_since_epoch();
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count() % 1000;
msg.formatted.write("[{:d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}.{:03d}] [{}] [{}] ",
msg.tm_time.tm_year + 1900,
msg.tm_time.tm_mon + 1,
msg.tm_time.tm_mday,
msg.tm_time.tm_hour,
msg.tm_time.tm_min,
msg.tm_time.tm_sec,
static_cast<int>(millis),
msg.logger_name,
level::to_str(msg.level));
msg.formatted.write(msg.raw.str());
/* Slower version(while still very fast - about 3.2 million lines/sec),
msg.formatted.write("[{:d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}.{:03d}] [{}] [{}] {} ",
msg.tm_time.tm_year + 1900,
msg.tm_time.tm_mon + 1,
msg.tm_time.tm_mday,
msg.tm_time.tm_hour,
msg.tm_time.tm_min,
msg.tm_time.tm_sec,
static_cast<int>(millis),
msg.logger_name,
level::to_str(msg.level),
msg.raw.str());*/
// Faster (albeit uglier) way to format the line (5.6 million lines/sec)
msg.formatted << '[' << msg.tm_time.tm_year + 1900 << '-'
<< fmt::pad(msg.tm_time.tm_mon + 1, 2, '0') << '-'
<< fmt::pad(msg.tm_time.tm_mday, 2, '0') << ' '
<< fmt::pad(msg.tm_time.tm_hour, 2, '0') << ':'
<< fmt::pad(msg.tm_time.tm_min, 2, '0') << ':'
<< fmt::pad(msg.tm_time.tm_sec, 2, '0') << '.'
<< fmt::pad(static_cast<int>(millis), 3, '0') << "] ";
msg.formatted << '[' << msg.logger_name << "] [" << level::to_str(msg.level) << "] ";
msg.formatted.write(msg.raw.data(), msg.raw.size());
}
};
......@@ -429,7 +443,7 @@ inline void spdlog::pattern_formatter::handle_flag(char flag)
{
switch (flag)
{
// logger name
// logger name
case 'n':
_formatters.push_back(std::unique_ptr<details::flag_formatter>(new details::name_formatter()));
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment