Boost logo

Boost :

Subject: Re: [boost] [lexical_cast] Fast conversion from boost::iterator_range<std::string::iterator>?
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2011-11-23 18:30:08


> On 11/23/2011 4:35 PM, Hartmut Kaiser wrote:
> >> On 11/23/2011 04:15 PM, Matthew Chambers wrote:
> >> The spirit code isn't really optimal (see the slightly improved
> >> version attached).
>
> OK. That would be nice in the docs...took me 15 minutes to figure out what
> I did have! :(
>
>
> >> Also, did you turn on optimization?
>
> I DID have optimization on but had some other junk on: debug symbols, /CLR
> (this was huge!), and the default _SECURE_SCL=1. After changing these, it
> got better but still not quite as good as MSVC 10.
> _SECURE_SCL was a major difference between MSVC9 and 10 (where it defaults
> to off).
>
>
> > Apparently not (MSVC2010, 64bit):
> >
> > 1000000 iterations of "123":
> > atoi: 0.0366391 seconds
> > strtol: 0.0327922 seconds
> > Spirit: 0.0117357 seconds
> > lexical_cast(string): 0.0702884 seconds
> > lexical_cast(iterator_range): 0.742229 seconds
> > lexical_cast(iterator_range->string): 0.0797006 seconds
> >
> > 1000000 iterations of "123567890":
> > atoi: 0.0489029 seconds
> > strtol: 0.0473159 seconds
> > Spirit: 0.0209374 seconds
> > lexical_cast(string): 0.0842183 seconds
> > lexical_cast(iterator_range): 1.02365 seconds
> > lexical_cast(iterator_range->string): 0.0912515 seconds
> >
> > 1000000 iterations of "1.23456":
> > atof: 0.295518 seconds
> > strtod: 0.279579 seconds
> > Spirit: 0.0308074 seconds
> > lexical_cast(string): 1.2818 seconds
> > lexical_cast(iterator_range): 2.15233 seconds
> > lexical_cast(iterator_range->string): 1.35335 seconds
> >
> > 1000000 iterations of "1.23456789e42":
> > atof: 0.422748 seconds
> > strtod: 0.407293 seconds
> > Spirit: 0.0479103 seconds
> > lexical_cast(string): 1.47888 seconds
> > lexical_cast(iterator_range): 2.61988 seconds
> > lexical_cast(iterator_range->string): 1.52793 seconds
> >
> > That's more like it :-P
>
>
> I added error checking to strto[dl] (what's the point of using it
> otherwise?).
>
> My new figures (32-bit):
>
> 1000000 iterations of "123":
> atoi: 0.0434303 seconds
> strtol: 0.0385471 seconds
> Spirit: 0.27993 seconds
> lexical_cast(string): 0.337947 seconds
> lexical_cast(iterator_range): 3.13472 seconds
> lexical_cast(iterator_range->string): 0.441562 seconds
>
> 1000000 iterations of "123567890":
> atoi: 0.0635996 seconds
> strtol: 0.0627828 seconds
> Spirit: 0.550669 seconds
> lexical_cast(string): 0.440172 seconds
> lexical_cast(iterator_range): 4.85826 seconds
> lexical_cast(iterator_range->string): 0.516084 seconds
>
> 1000000 iterations of "1.23456":
> atof: 0.495972 seconds
> strtod: 0.507613 seconds
> Spirit: 0.685259 seconds
> lexical_cast(string): 2.74444 seconds
> lexical_cast(iterator_range): 4.62169 seconds
> lexical_cast(iterator_range->string): 2.8685 seconds
>
> 1000000 iterations of "1.23456789e42":
> atof: 0.700639 seconds
> strtod: 0.707499 seconds
> Spirit: 0.967519 seconds
> lexical_cast(string): 3.16936 seconds
> lexical_cast(iterator_range): 6.19912 seconds
> lexical_cast(iterator_range->string): 3.29152 seconds
>
>
> Arash Partow pointed me at his thorough article:
> http://www.codeproject.com/KB/recipes/Tokenizer.aspx
>
> Based on Boost 1.48 (not sure how many performance changes went into
> lexical_cast between 1.47 and
> 1.48). He's using Profile Guided Optimization though; it seems to make a
> big difference which has
> not been my experience in bigger projects.

Something is definitely fishy with your Spirit numbers.

Regards Hartmut
---------------
http://boost-spirit.com
http://stellar.cct.lsu.edu


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