Boost logo

Boost :

Subject: Re: [boost] Boost.Convert. Take 2.
From: Vladimir Batov (vb.mail.247_at_[hidden])
Date: 2014-02-21 03:12:08


Rob Stewart <robertstewart <at> comcast.net> writes:
> On February 20, 2014 6:27:42 PM EST, Vladimir Batov <Vladimir.Batov <at>
constrainttec.com> wrote:
> >On 02/21/2014 08:31 AM, Edward Diener wrote:
> >> On 2/16/2014 3:56 PM, Vladimir Batov wrote:
> >
> >> I think you have successfully focused on what is needed for a more
> >> flexible lexical_cast-like version this time.
> >>
> >
> >I am especially surprised by the fact that its performance seems quite
> >adequate (without any optimization):
> [snip]
> >tests. On the other hand the test could not be any more
> >straightforward:
> >
> > double p4 = clock();
> >
> > for (int k = 0; k < local::num_cycles; ++k)
> > sscanf("12345", "%d", &v);
> >
> > double p5 = clock();
> >
> > for (int k = 0; k < local::num_cycles; ++k)
> > boost::lexical_cast<int>("12345");
> >
> > double p6 = clock();
> >
> > for (int k = 0; k < local::num_cycles; ++k)
> > boost::convert<int>::from("12345", ccnv).value();
> >
> > double p7 = clock();
> >
> > printf("scanf/lcast/convert=%.2f/%.2f/%.2f seconds.\n",
> > (p5 - p4) / CLOCKS_PER_SEC,
> > (p6 - p5) / CLOCKS_PER_SEC,
> > (p7 - p6) / CLOCKS_PER_SEC);
>
> I assume you're timing an optimized build, on which case you are being
misled by the optimizer because
> you're not using the results of the conversions.

Rob,

Nice hearing from you. I had that suspicion also and I do not think
optimization was at play. The reason is that I timed twice with "-g" and
without and definitely did not have optimization flags (never use them). And
it's hard not to notice when the code is optimized -- stepping through is,
well, difficult. :-) Secondly, my actual code is different (for the post I
cut it to bare minimum). All loops are actually like

for (int k = 0; k < local::num_cycles; ++k)
{
    int k = boost::convert<int>::from("12345", ccnv).value();
    BOOST_ASSERT(k == 12345);
}

Do you think there still might be something I missed?


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