Fixed timer code for Mac (PR_Now wasn't doing the trick). Now using |nsInt64| instead of implementing my own |operator-()|

This commit is contained in:
scc%netscape.com 2000-03-29 08:14:09 +00:00
parent e275624147
commit 6e2cad434e

View File

@ -1,14 +1,17 @@
// profile_main.cpp
#include "nscore.h"
#include "prlong.h"
#include "prtime.h"
#include <iostream.h>
#include <string>
#include <iomanip>
#include "nsInt64.h"
#ifdef XP_MAC
#include <Timer.h>
#include "Profiler.h"
#else
#include "prtime.h"
#endif
#ifndef TEST_STD_STRING
@ -56,37 +59,37 @@ Find( const string& text, const string& pattern )
return text.find(pattern);
}
#ifndef HAVE_LONG_LONG
inline
PRUint64
operator-( const PRUint64& lhs, const PRUint64& rhs )
nsInt64
GetTime()
{
PRInt64 result;
LL_SUB(result, lhs, rhs);
return result;
}
#ifdef XP_MAC
UnsignedWide time;
Microseconds(&time);
return nsInt64( *reinterpret_cast<PRInt64*>(&time) );
#else
return nsInt64( PR_Now() );
#endif
}
class TestTimer
{
public:
TestTimer() : mStartTime(PR_Now()) { }
TestTimer() : mStartTime(GetTime()) { }
~TestTimer()
{
PRTime stopTime = PR_Now();
PRTime totalTime = stopTime - mStartTime;
nsInt64 stopTime = GetTime();
nsInt64 totalTime = stopTime - mStartTime;
#ifdef HAVE_LONG_LONG
cout << setw(10) << totalTime << " µs : ";
cout << setw(10) << NS_STATIC_CAST(PRInt64, totalTime) << " µs : ";
#else
if ( totalTime.hi )
cout << "*";
cout << setw(10) << totalTime.lo << "µs : ";
cout << setw(10) << NS_STATIC_CAST(PRInt32, totalTime) << "µs : ";
#endif
}
private:
PRTime mStartTime;
nsInt64 mStartTime;
};
static