on the speed of std::string::find

Dennis Lubert plasmahh@projectiwear.org
Fri Sep 1 13:25:00 GMT 2006


Am Freitag, den 01.09.2006, 14:30 +0200 schrieb Paolo Carlini: 
> Dennis Lubert wrote:
> 
> >  
> >
> Likewise good point ;) Yes, in various parts of the library, locale for 
> instance, we are putting to good use very convenient gnu extensions, 
> therefore the plan makes sense. Well, we have to study the issue a bit 
> more and see whether the added complexity is worth the improvement (from 
> a maintainance point of view too).
>From a maintainance pov I think its not much more to call memmem instead
of std::search (and of course sort out the different parameters, and
different returns, but its just similar enough).

Attached is a small test that I hacked together. Its not very accurate
and clean etc. but it should show that memmem is ~1.5 times faster in
this case.
Be aware that this program needs to be compiled without any optimization
(on irc I had the report that it even only works when you explicitly set
-O0) otherwise the memmem call will be eliminitaed outside the loop
completely.

greets

Dennis

PS: playing around with the strings can vary the factor a lot it seems.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fullwatch.cpp
Type: text/x-c++src
Size: 2387 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20060901/3e03c695/attachment.bin>


More information about the Libstdc++ mailing list