iPhone: High-resolution time?
Thanks!
-Chris
iPhone, Mac OS X (10.5.4), iPhone Developer
Developer Forums relocated!
Need help with Apple Developer tools and technologies? Want to share information with other developers and Apple engineers? Visit Developer Forums at Apple.
Need help with Apple Developer tools and technologies? Want to share information with other developers and Apple engineers? Visit Developer Forums at Apple.
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?