Release of C++ Format 1.0, a small, safe and fast formatting library for C++--Victor Zverovich

Add a Comment

Comments are closed.

Comments (7)

2 0

Bjarne Stroustrup said on Feb 9, 2015 10:46 AM:

are the speed measures done with sync_with_stdio(false)?
2 0

d-marc said on Feb 9, 2015 07:03 PM:

@Bjarne Stroustrup

Yes, (see https://github.com/cppformat/format-benchmark/blob/master/tinyformat_test.cpp).

But I am sure we can optimize this:


for(long i = 0; i < maxIter; ++i)
std::cout << std::setprecision(10) << std::fixed << 1.234 << ":"
<< std::resetiosflags(std::ios::floatfield)
<< std::setw(4) << std::setfill('0') << 42 << std::setfill(' ') << ":"
<< std::setiosflags(std::ios::showpos) << 3.13 << std::resetiosflags(std::ios::showpos) << ":"
<< "str" << ":"
<< (void*)1000 << ":"
<< 'X' << ":%\n";
2 0

vitaut said on Feb 10, 2015 11:45 AM:

@d-marc

Let me know if you can come up with an optimized version of the IOStreams code and I'll update the benchmark. This one originates from the Tinyformat library. I've also looked at integer formatting and Boost Karma's benchmark here: http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html.
1 0

d-marc said on Feb 10, 2015 04:00 PM:

I think it could help if the string literals with a length of one character would be replaced by character literals. Simply replace all occurrences of ":" by ':'. This avoids calling strlen() or some equivalent to figure out the length of the string all the time.
1 0

vitaut said on Feb 10, 2015 08:41 PM:

It did help a bit reducing the gap between ostream and printf from 63% to 42%. Although the change might be partly due to a different version of the standard library as I used a new system.
0 0

voidstar said on Jan 13, 2016 09:12 AM:

Victor (or anyone), have you benchmarked this relative to Qt QStrings? I haven't looked at how QStrings are implemented (to see if they are a wrapper or have their own native implementation that might be on par with cppformat?). Would be interested in the results.
0 0

vitaut said on Jan 13, 2016 09:22 AM:

@voidstar No, I haven't benchmarked QStrings.