This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: on the speed of std::string::find


Am Freitag, den 01.09.2006, 13:09 +0200 schrieb Paolo Carlini:
> Dennis Lubert wrote:
> 
> >Hello,
> >
> >I recently did some profiling of my application (compiled with gcc 4.1)
> >using callgrind (part of valgrind). I found out that the good old
> >std::strstr is between 4 and 20 times faster than std::string::find.
> >
> First, which version of gcc are you using? 

Please look up, its gcc 4.1.

> Recent versions simply 
> delegate to the std::search in <algorithm>, which was benchmarked to be 
> much faster than an algorithm based on char_traits::find, thus memchr, 
> basically. Of course we are talking here about the overload of 
> string::find exactly corresponding to strstr (that is, search a whole 
> string inside another one), because the other, "simpler", overloads, all 
> delegate already to memchr (via char_traits::memchr).

Yes, my version mainly delegates to std::search (only for the search for
a single character, it delegates to char_traits::find).
So yes, we talk about the overload of those std::string::find variants
that can be directly mapped to std::strstr. (Something that just came to
my mind -- but I have no idea if its possible -- is if its possible
and/or useful to try to overload std::search for char* to use strstr or
to take the strstr implementation as a base for a faster std::search
specialization for char*)

greets

Dennis


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]