// profile_main.cpp #include "nscore.h" #include #include #include #include "nsInt64.h" #ifdef XP_MAC #include #include "Profiler.h" #else #include "prtime.h" #endif #ifndef TEST_STD_STRING #include "nsString.h" #else #include "nsStdStringWrapper.h" typedef nsStdCString nsCString; #endif static const int kTestSucceeded = 0; static const int kTestFailed = 1; static const size_t N = 100000; 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 nsInt64 GetTime() { #ifdef XP_MAC UnsignedWide time; Microseconds(&time); return nsInt64( *reinterpret_cast(&time) ); #else return nsInt64( PR_Now() ); #endif } class TestTimer { public: TestTimer() : mStartTime(GetTime()) { } ~TestTimer() { nsInt64 stopTime = GetTime(); nsInt64 totalTime = stopTime - mStartTime; #ifdef HAVE_LONG_LONG cout << setw(10) << NS_STATIC_CAST(PRInt64, totalTime) << " µs : "; #else cout << setw(10) << NS_STATIC_CAST(PRInt32, totalTime) << "µs : "; #endif } private: nsInt64 mStartTime; }; inline int foo( const nsCString& ) { return 1; } static int test_construction() { cout << endl; { nsCString someCString; int total = 0; TestTimer timer; for ( int i=0; i s2 ) ++count; } cout << "s1 > s2" << endl; { TestTimer timer; for ( int i=0; i