Re: STL Slow - VS2005



Here is the file that was tested with vs2005 stl and vs2005 w/stlport 5.0



// string_compare.cpp : Defines the entry point for the console application.
//
#include <cstdio>
#include <string>


// This DEFINE is needed for VC6.
// IN VC8 namespace std is used
#ifdef USE_STLPORT
#pragma message ("USING STLPORT")
using namespace stlport;
#else
using namespace std;
#endif

string func(string par )
{
string tmp(par);
return tmp ;
}

string func2(string& par )
{
string tmp(par);
return tmp ;
}


int main ( int , char* const* )
{
HighResPerformanceMeasurement usecTimer;

{
usecTimer.Start();
string s ;
for ( int i = 0 ; i < 100000000; ++ i ) {
s += " " ;
}
usecTimer.End();
double msecs =
double((usecTimer.GetDifference()*1000)/usecTimer.GetFrequency());
printf("Append one character to empty string 100 million times: %.0f
ms\n", msecs);
}

{
usecTimer.Start();
string s("qyweyuewunfkHBUKGYUGL ,wehbYGUW^( @T@H!BALWD:h^&@#*@(#:
JKHWJ:CND");
for (int i = 0 ; i < 10000000; ++i) {
s.find( "unfkHBUKGY" ) ;
s.find( "W^( @T@H!B" ) ;
s.find( "J:CND" ) ;
}
usecTimer.End();
double msecs =
double((usecTimer.GetDifference()*1000)/usecTimer.GetFrequency());
printf("Search long string for 3 different substrings 10 million times:
%.0f ms\n", msecs);
}

{
usecTimer.Start();
string s("qyweyuewunfkHBUKGYUGL ,wehbYGUW^( @T@H!BALWD:h^&@#*@(#:
JKHWJ:CND");
string::size_type p ;
string ss1( "unfkHBUKGY");
string ss2 ( "123456" ) ;
string sx ;
for ( int i = 0 ; i < 10000000; ++ i ) {
sx = s ;
p = sx.find ( ss1 ) ;
sx.replace ( p , ss1.size() , ss2 ) ;
sx += s ;
}
usecTimer.End();
double msecs =
double((usecTimer.GetDifference()*1000)/usecTimer.GetFrequency());
printf("Assignment, search, replace 10 million times: %.0f ms\n", msecs);
}

{
usecTimer.Start();
string s("qyweyuewunfkHBUKGYUGL ,wehbYGUW^( @T@H!BALWD:h^&@#*@(#:
JKHWJ:CND");
for( int i = 0 ; i < 10000000; ++ i ) {
string sx = func( s );
}
usecTimer.End();
double msecs =
double((usecTimer.GetDifference()*1000)/usecTimer.GetFrequency());
printf("Pass and return by value function called 10 million times: %.0f
ms\n", msecs);
}

{
usecTimer.Start();
string s("qyweyuewunfkHBUKGYUGL ,wehbYGUW^( @T@H!BALWD:h^&@#*@(#:
JKHWJ:CND");
for( int i = 0 ; i < 10000000; ++ i ) {
string sx = func2( s );
}
usecTimer.End();
double msecs =
double((usecTimer.GetDifference()*1000)/usecTimer.GetFrequency());
printf("Pass by reference return by value function called 10 million
times: %.0f ms\n", msecs);
}

{
usecTimer.Start();
string s("1234567890");
for( int i = 0 ; i < 10000000; ++ i ) {
string sx = func( s );
}
usecTimer.End();
double msecs =
double((usecTimer.GetDifference()*1000)/usecTimer.GetFrequency());
printf("Short String - Pass and return by value function called 10 million
times: %.0f ms\n", msecs);
}

return 0 ;
}


"Carl Daniel [VC++ MVP]" wrote:

"WXS" <WXS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B3C45289-3843-4465-BC3B-BE287471DD4C@xxxxxxxxxxxxxxxx
VS2005
We compared the MS STL with stlport5.0 and found the results so
significantly slow as to make us question the implementation. Here is an
output of our tester compiled under vs2005 comparing vs2005's stl with
stlport 5.0's stl implementation.

Anyone else seeing the same or know how to improve performance? We tried
enabling small block allocation and setting the security checks define to
0
but no luck, performance got even worse.

Without knowing exactly how you built the code, and exactly what the code is
doing, it's impossible to comment beyond the superficial.

Can you post your test program for others to inspect and verify your
results?

-cd



.



Relevant Pages

  • Re: basic_string causes crash in _vsnprintf???
    ... > this functionality so while it was not a standard STL implementation ... In STLport it's just luck that it "works". ... The first pointer points to the start of the string, ... > So the code is not proper to the STL standard baseline implementation ...
    (microsoft.public.vc.stl)
  • Re: basic_string causes crash in _vsnprintf???
    ... and any other output string sets used. ... want or revert back to the old stl. ... >> this functionality so while it was not a standard STL implementation ... > In STLport it's just luck that it "works". ...
    (microsoft.public.vc.stl)
  • Re: Basic question : Replacing CString when moving from MFC to Win32
    ... "use STL", but I don't use STL, and am not qualified to tell you if that will solve the ... If you want to be able to "strcat", study the CString implementation carefully. ... If memory fragmentation becomes an issue, you can write a storage compactor; ... and a way to find all the string pointers. ...
    (microsoft.public.vc.mfc)
  • Re: Benchmark: STLs list vs. hand-coded one
    ... STL strings and in particular string concatenation. ... but very likely it is the memory allocation. ...
    (comp.arch.embedded)
  • Re: Benchmarks: STLs string vs. C string
    ... about STL being 50x slower in string concatenation, ... faster than C style string manipulation, ... JavaDoc it is said what is the time and/or space complexity of these operations) ...
    (comp.arch.embedded)

Loading