The performance of format degraded after #1815. Profiling shows that _Getcvt() is consuming a significant part of the CPU time.
We could investigate:
- Avoid calling
_Getcvt() when unnecessary (when the format string is interpreted as UTF-8 or UTF-16).
- Reduce the number of calls to
_Getcvt().
#include <chrono>
#include <format>
#include <iostream>
#include <iterator>
#include <ratio>
using namespace std;
using namespace std::chrono;
int main() {
constexpr int iters = 10'000'000;
string buf;
buf.reserve(64);
size_t dummy = 0;
const auto start_time = steady_clock::now();
for (int i = 0; i < iters; ++i) {
buf.clear();
format_to(back_inserter(buf), "run {0}/{1}", i + 1, iters);
dummy += buf.size();
}
const auto end_time = steady_clock::now();
const auto average_time = duration<double, nano>{end_time - start_time} / iters;
cout << "average time: " << average_time << "\n";
cout << format("dummy: {}\n", dummy);
}
cl /EHsc /W4 /WX /std:c++latest /O2 /utf-8 temp.cpp
Before #1815: 179 ns
After #1815: 241 ns
The performance of
formatdegraded after #1815. Profiling shows that_Getcvt()is consuming a significant part of the CPU time.We could investigate:
_Getcvt()when unnecessary (when the format string is interpreted as UTF-8 or UTF-16)._Getcvt().Before #1815: 179 ns
After #1815: 241 ns