From: Matthew Hurd (matt_at_[hidden])
Date: 2003-11-07 21:28:05
Replying to myself...
> On Behalf Of Matthew Hurd
> Sent: Saturday, 8 November 2003 8:17 AM
> To: 'Boost mailing list'
> Subject: RE: [boost] String thought
> result b_ + c_ + b_ + c_ = and is this it and it doesn't seem much at all
> and is this it and it doesn't seem much at all
> time taken =
> result b + c + b + c = and is this it and it doesn't seem much at all and
> this it and it doesn't seem much at all
> time taken =
> Press any key to continue . . .
Interestingly if the strings are quite long... the vc7.1 std::string is
faster which was counter to my thinking. Makes senses if the slow
expression template string copy is dominating though I guess.
I get 10.031 seconds for the e.t. and 4.281 seconds for the std::string.
Changed the copy to use copy instead of operator copying to see if this is
Much better results:
Expr template std::string Speed up
Shorter with dumb 1.171 2.422 2.1
with copy 0.140 2.594 18.5
Longer with dumb 10.031 4.281 0.4
with copy 0.321 4.109 12.8
Lone char with dumb 0.056 0.369 6.6
with copy 0.110 0.369 3.4
(tested x10 to improve accuracy..., dumb is not so dumb ;-) here )
So I guess the expression template for concatenating four strings together
gives us between 3 and 18 times speed up depending on the length of the
Does this mean this implementation std::string is slow? No, not really.
What if we change
a = b + c + b + c;
a = b;
a += c;
a += b;
a += c;
to give the std::string a bit of a hand...
for a shorter length string we get:
expression template = 0.139 seconds
long hand std::string = 0.161 seconds
Not a lot in it, the long hand std::string is paying for the extra resizing
for each statement I'd guess. The conclusion might be that there is no
magic just elimination of proxies for the expression template, which is what
Convenience and speed for the user versus a more complicated library...
I can't see how to inject this into std to make it practical for a user...
it would have to be the library writer. Is that true? Beyond me...
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.536 / Virus Database: 331 - Release Date: 3/11/2003