iPhone: High-resolution time?
Thanks!
-Chris
iPhone, Mac OS X (10.5.4), iPhone Developer
Apple Intelligence is now available on iPhone, iPad, and Mac!
iPhone, Mac OS X (10.5.4), iPhone Developer
//
// MachTimer.h
//
#include <assert.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <unistd.h>
@interface MachTimer : NSObject {
uint64_t t0;
}
- (void)start;
- (uint64_t)elapsed;
- (float)elapsedSec;
@end
//
// MachTimer.m
//
#import "MachTimer.h"
static machtimebase_info_datat timebase;
@implementation MachTimer
+ (void)initialize
{
(void) machtimebaseinfo(&timebase);
}
- init
{
if(self = [super init]) {
t0 = machabsolutetime();
}
return self;
}
- (void)start
{
t0 = machabsolutetime();
}
- (uint64_t)elapsed {
return machabsolutetime() - t0;
}
- (float)elapsedSec {
return ((float)(machabsolutetime() - t0)) * ((float)timebase.numer) / ((float)timebase.denom) / 1000000000.0f;
}
@end
iPhone: High-resolution time?