> People aren't telling you that Bjarne's terrible I/O streams functionality is great so you should use that.
Well, std::format is what you actually told me I was a fool and a noob for refusing to use under the pretense of being pragmatic. ("you are deliberately choosing to use poor tools and calling this "pragmatism" because it sounds better than admitting you're bad at this and you don't even want to improve")
So I've finally put in the work and made std::format run on MSVC because that's the only compiler where std::format is available for me (gcc-12 and clang-14 don't include it on my Debian VM).
And guess what, simple file with main() and std::format("Hello {}\n", 42) + fwrite() takes 1.4 seconds to compile there (no linking, no optimizations) compared to 0.16s for compiling a cpp file with the equivalent snprintf/fwrite call.
0.16s is still much but MSVC takes 0.12s for compiling "return 0". Subtracting that, it's a somewhat reasonable overhead of 0.04s for including + using stdio.h / snprintf. And 1.28s, so literally 32x that amount, and realistically a nerve wrecking time to wait for a single file to compile, for the std::format version.
I'm not sure how to take you seriously anymore. It's hard to imagine you've actually used this yourself, because paying more than a second to compile a single print statement is not OK. I wish people like you would just be a little less loud and more considerate when judging people that are trying to actually get something done.
The code under test:
#include <format>
#include <string>
#include <stdio.h>
int main()
{
std::string x = std::format("Hello {}\n", 42);
fwrite(x.data(), 1, x.size(), stdout);
return 0;
}
$ cl /version
Microsoft (R) C/C++ Optimizing Compiler Version 19.35.32216.1 for x64
Here is a godbolt where gcc-13 with fmtlib setup (as a library) is tested against stdio.h printf(). It's 600-1200ms for std::print(...) vs 60-120ms for printf(...) and just a few ms less for "return 0". (timings are highly variable on godbolt). Again, an overhead of probably some 20x-100x compared to stdio.h printf when we subtract the time for compiling "return 0".
https://godbolt.org/z/Pa4jh8qbz