Boost logo

Boost :

Subject: Re: [boost] Boost.Convert. Take 2.
From: Vladimir Batov (Vladimir.Batov_at_[hidden])
Date: 2014-02-20 18:27:42

On 02/21/2014 08:31 AM, Edward Diener wrote:
> On 2/16/2014 3:56 PM, Vladimir Batov wrote:
>> Addressed all three comments... I think. Checked in.
> This looks good.

Thanks, Edward, it's much appreciated.

> 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):

user-defined type: lcast/convert=0.52/0.27 seconds.
int type: scanf/lcast/convert=0.12/0.16/0.21 seconds.

It beats lexical_cast for user-defined types and not that far behind for
built-in types (I tested with "int"). I have a few doubts though
regarding the performance tests as lexical_cast documentation lists
quite different results:

scanf: 24
string-to-int 7
std::stringstream without construction (my convert): 20

and puts lexical_cast so far in front for gcc 4.6.3 that I used for
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)

     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 have to say that when I read my own :-) documentation I do feel that
"convert" provides quite useful functionality and quite a step forward
compared to frugal lexical_cast (well, for my use anyway). What concerns
me though is that when I look at the code, I think -- is it all?! There
is so little of it that I can't help thinking -- I must be missing
something monumental.


Boost list run by bdawes at, gregod at, cpdaniel at, john at