mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-11 16:32:59 +00:00
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:
parent
e275624147
commit
6e2cad434e
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user