On February 21, 2014 12:21:12 PM EST, alex
-----Original Message----- From: Boost [mailto:boost-bounces@lists.boost.org] On Behalf Of Rob Stewart Sent: 21 February 2014 15:35 To: boost@lists.boost.org Subject: Re: [boost] Boost.Convert. Take 2.
On February 21, 2014 5:48:32 AM EST, alex
wrote: 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?
The assertion won't help in an optimized build, of course. Save the values and print them at the end, after you've captured the elapsed times.
Isn't it also a problem that the inside of the loop doesn't vary? A smart compiler may decide to evaluate boost::convert<int>::from("12345", ccnv).value() only once and re-use the result?
Of course, yes. I should have noticed that. Incrementing a value each iteration and printing that value at the end should work. Overflow isn't important. Just using the final value in an opaque way will prevent optimizing away the conversions in the loops.
That seems easier said than done, because it is the value of a string that needs to be unpredictable?
int sum = 0; for (int k = 0; k < local::num_cycles; ++k) { char str[] = "12345"; str[4 - k % 5] = 49 + k % 9; //because the char '1' has value 49 sum += boost::convert<int>::from(str, ccnv).value(); } std::cout << sum;
I'm not sure that's necessary. Unless there is a lot more inlining than I'm imagining, I don't think the optimizer will cause a problem with the string literal input. ___ Rob (Sent from my portable computation engine)