mirror of
https://github.com/yuzu-emu/FasTC.git
synced 2024-11-28 05:14:17 +01:00
Switch OSX timer to real-time too.
This commit is contained in:
parent
f2b9c39801
commit
7b69c38da5
@ -3,24 +3,20 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <mach/mach_time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
class StopWatchImpl {
|
||||
public:
|
||||
uint64 start;
|
||||
|
||||
double resolution;
|
||||
double duration;
|
||||
|
||||
StopWatchImpl() {
|
||||
mach_timebase_info_data_t info;
|
||||
mach_timebase_info(&info);
|
||||
|
||||
resolution = double(info.numer) / double(info.denom);
|
||||
resolution *= 1e-9;
|
||||
}
|
||||
uint64 duration;
|
||||
};
|
||||
|
||||
static uint64 Now() {
|
||||
timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_usec + (1e6 * tv.tv_sec);
|
||||
}
|
||||
|
||||
StopWatch::StopWatch(const StopWatch &other) {
|
||||
impl = new StopWatchImpl();
|
||||
memcpy(impl, other.impl, sizeof(StopWatchImpl));
|
||||
@ -43,11 +39,11 @@ StopWatch::StopWatch() : impl(new StopWatchImpl) {
|
||||
}
|
||||
|
||||
void StopWatch::Start() {
|
||||
impl->start = mach_absolute_time();
|
||||
impl->start = Now();
|
||||
}
|
||||
|
||||
void StopWatch::Stop() {
|
||||
impl->duration = impl->resolution * (double(mach_absolute_time()) - impl->start);
|
||||
impl->duration = Now() - impl->start;
|
||||
}
|
||||
|
||||
void StopWatch::Reset() {
|
||||
@ -55,13 +51,13 @@ void StopWatch::Reset() {
|
||||
}
|
||||
|
||||
double StopWatch::TimeInSeconds() const {
|
||||
return impl->duration;
|
||||
return double(impl->duration) / 1e6;
|
||||
}
|
||||
|
||||
double StopWatch::TimeInMilliseconds() const {
|
||||
return impl->duration * 1000;
|
||||
return double(impl->duration) / 1e3;
|
||||
}
|
||||
|
||||
double StopWatch::TimeInMicroseconds() const {
|
||||
return impl->duration * 1000000;
|
||||
return double(impl->duration);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user