This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
on the speed of std::string::find
- From: Dennis Lubert <plasmahh at projectiwear dot org>
- To: libstdc++ at gcc dot gnu dot org
- Date: Fri, 01 Sep 2006 12:59:46 +0200
- Subject: on the speed of std::string::find
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.
So what I wonder now is, why are those std::string::find variants where
its possible not implemented via a call to std::strstr? The internal
string representation already seems to be null terminated (c_str()
returns _M_data() which just returns _M_dataplus._M_p). So there could
be specializations for std::string::find that could use that
implementation. (all those that take strings, c-strings and the pos
parameter only. for those with a maximum n parameter of course strstr
cannot be used. but maybe a modified version?)
So by replacing most critical std::string::find calls by (wrapped) calls
to std::strstr I could speed up my app quite a lot, and I wonder why its
not also used for std::find. Did I overlook something?
greets
Dennis