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 17:35:16


> On 11/23/2011 04:15 PM, Matthew Chambers wrote:
> > On 11/23/2011 4:13 PM, Matthew Chambers wrote:
> >> I put together a test (http://codepad.org/lKxMXOwP):
> >>
> >> 1000000 iterations of "123":
> >> atoi: 0.0695092 seconds
> >> strtol: 0.0652839 seconds
> >> Spirit: 0.546789 seconds
> >> lexical_cast(string): 0.615594 seconds
> >> lexical_cast(iterator_range): 4.25534 seconds
> >> lexical_cast(iterator_range->string): 1.07405 seconds
> >>
> >> 1000000 iterations of "123567890":
> >> atoi: 0.0856611 seconds
> >> strtol: 0.0829571 seconds
> >> Spirit: 0.905017 seconds
> >> lexical_cast(string): 0.762137 seconds
> >> lexical_cast(iterator_range): 7.46185 seconds
> >> lexical_cast(iterator_range->string): 1.23397 seconds
> >>
> >> 1000000 iterations of "1.23456":
> >> atof: 0.520452 seconds
> >> strtod: 0.519113 seconds
> >> Spirit: 1.02579 seconds
> >> lexical_cast(string): 2.93515 seconds
> >> lexical_cast(iterator_range): 6.62648 seconds
> >> lexical_cast(iterator_range->string): 3.73831 seconds
> >>
> >> 1000000 iterations of "1.23456789e42":
> >> atof: 0.711819 seconds
> >> strtod: 0.719144 seconds
> >> Spirit: 1.48992 seconds
> >> lexical_cast(string): 3.31997 seconds
> >> lexical_cast(iterator_range): 9.87004 seconds
> >> lexical_cast(iterator_range->string): 4.20932 seconds
> >
> > I forgot to say the test environment:
> > boost 1.47
> > MSVC 9 SP1
> > Core 2 Q9400
> >
> > -Matt
>
> The spirit code isn't really optimal (see the slightly improved version
> attached). Also, did you turn on optimization?

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

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