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]

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


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