Boost logo

Boost :

Subject: Re: [boost] [convert] Performance
From: Vladimir Batov (Vladimir.Batov_at_[hidden])
Date: 2014-06-09 23:06:25


On 05/26/2014 04:26 PM, Joel de Guzman wrote:
> On 5/25/14, 6:34 PM, Jeroen Habraken wrote:
>> That said I'm well aware this isn't easy, I was delighted to have
>> boost::coerce reviewed in [4] without my input. At times a mail would
>> also
>> pop up complaining my library stopped working in the latest version of,
>> surprise, MSVC. I have no idea who's using it though unfortunately.
> >
> > [...]
> >
> > [4] http://www.kumobius.com/2013/08/c-string-to-int/
>
> This makes me wonder. How fast is Convert BTW? How does it compare
> to the examples in that benchmark? Boost is performance hungry! It
> will be a real cause of concern if it is slower than the benchmarks.

I wrote a half-hearted spirit-based converter and a performance test and
got something I personally cannot explain. Can anyone help me to solve
the puzzle?

First, I compiled with -O3 using

~/dev/boost.convert/doc >> gcc --version
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3

and get quite encouraging (even though hardly unexpected) results:

str-to-int spirit: raw/cnv=0.28/0.28 seconds.
str-to-int spirit: raw/cnv=0.28/0.28 seconds.

where "raw" is a straight invocation of

inline int str_to_int_spirit(std::string const& str)
{
     std::string::const_iterator i = str.begin();
     int result;

     BOOST_TEST(boost::spirit::qi::parse(i, str.end(),
boost::spirit::int_, result));
     BOOST_TEST(i == str.end()); // ensure the whole string was parsed

     return result;
}

and "cnv" is that same code wrapped-in as a converter. So far so good.
No performance penalty for deploying conversion facilities via
boost::convert().

Then though I tried that same code with gcc-4.8 on Ubuntu 14.04 32-bit
architecture (oldish) machine... and got something I cannot get my head
around of:

str-to-int spirit: raw/cnv=1.44/1.41 seconds.
str-to-int spirit: raw/cnv=1.44/1.41 seconds.

That is, gcc-4.8 applies some magic so that that same code wrapped in a
converter is 2% faster(!) than "raw" code. Is anyone curious and capable
to solve the puzzle? I am admittedly the former but not the latter. :-(

https://github.com/yet-another-user/boost.convert/blob/master/test/performance.cpp


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk