-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
chronoC++20 chronoC++20 chronoformatC++20/23 formatC++20/23 formatperformanceMust go fasterMust go faster
Description
Is this a known issue or am I doing something sub-optimal?
I'm simply calling
std::format_to( std::back_inserter( buffer ), "[{:%H:%M:%S}] ", time );
where buffer is a std::string and time is of type std::chrono::system_clock::duration
and this is about 4-5 times slower than 'rolling my own' e.g.
static constexpr auto h = 3600'000'000'000LL;
static constexpr auto min = 60'000'000'000LL;
static constexpr double sec = 1'000'000'000;
auto elapsed_ns = time.count();
const auto hours = elapsed_ns / h; elapsed_ns -= hours * h;
const auto minutes = elapsed_ns / min; elapsed_ns -= minutes * min;
const double seconds = elapsed_ns / sec;
std::format_to( std::back_inserter( buffer ), "[{}:{:02}:{:010.7f}] ", hours, minutes, seconds );
Not sure where this huge difference can come from. Allocations?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
chronoC++20 chronoC++20 chronoformatC++20/23 formatC++20/23 formatperformanceMust go fasterMust go faster