// profile_main.cpp #include "nscore.h" #include "prlong.h" #include #include #include #include "Profiler.h" #ifndef TEST_STD_STRING #include "nsString.h" #else #include "nsStdStringWrapper.h" typedef nsStdCString nsCString; #endif #include static const int kTestSucceeded = 0; static const int kTestFailed = 1; #if 0 #define N 1000 #else #define N 100000 #endif template inline PRUint32 TotalLength( const T& s ) { return s.Length(); } NS_SPECIALIZE_TEMPLATE inline PRUint32 TotalLength( const string& s ) { return s.length(); } template inline PRUint32 Find( const T& text, const T& pattern ) { return text.Find(pattern); } NS_SPECIALIZE_TEMPLATE inline PRUint32 Find( const string& text, const string& pattern ) { return text.find(pattern); } inline UnsignedWide operator-( const UnsignedWide& lhs, const UnsignedWide& rhs ) { PRInt64 a = LL_INIT(lhs.hi, lhs.lo); PRInt64 b = LL_INIT(rhs.hi, rhs.lo); PRInt64 c; LL_SUB(c, a, b); UnsignedWide result = {c.hi, c.lo}; return result; } class TestTimer { public: TestTimer() { Microseconds(&mStartTime); } ~TestTimer() { UnsignedWide stopTime; Microseconds(&stopTime); UnsignedWide totalTime = stopTime - mStartTime; if ( totalTime.hi ) cout << "*"; cout << setw(10) << totalTime.lo << " µs : "; } private: UnsignedWide mStartTime; }; static int test_concat() { //---------|---------|---------|---------|---------|---------|---------| nsCString s1("This is a reasonable length string with some text in it and it is good."); nsCString s2("This is another string that I will use in the concatenation test."); nsCString s3("This is yet a third string that I will use in the concatenation test."); PRUint32 len = TotalLength( s1 + s2 + s3 + s1 + s2 + s3 ); if ( len != (71 + 65 + 69 + 71 + 65 + 69) ) { cout << "|test_concat()| FAILED" << endl; return kTestFailed; } { TestTimer timer; for ( int i=0; i s2 ) ++count; } cout << "s1 > s2" << endl; { TestTimer timer; for ( int i=0; i