From: Paul G. <pga...@at...> - 2002-11-14 23:30:29
|
> Hi all > > Take this little program: > > #include <iostream> > #include <string> > #include <windows.h> > using namespace std; > > int main() > { > string str = "0123456789abc"; > > unsigned long start = GetTickCount(); > for (int i = 0; i < 10000000; ++i) > { > str.find("abc"); > } > unsigned long stop = GetTickCount(); > cout << (stop - start) / 1000.0 << endl; > } > > I've compiled it with gcc 3.2's libstdc++ and with stlport 5.0 > both with -O3 switch, and here the results: > libstdc++: > 5.75s, 5.75s, 5.75s > stlport: > 0.843s, 0.859s, 0.844s > > With: strstr(str.c_str(), "abc") took only: > 0.484s, 0.469s, 0.484s > > I don't know why the libstdc++ find is 6.8 times slower than > stlport find! At a guess, I think it may be due to the fact that libstdc++ does a much more detailed search based on the string in question, whereas stlport does a much more generic search of the string in question. Take a look at the actual stlport version of strstr vs. the actual libstdc++ version of strstr as it may be something that can give you a better idea of the functionality differences between the two methods. Paul G. |