iPhone: High-resolution time?
Thanks!
-Chris
iPhone, Mac OS X (10.5.4), iPhone Developer
Want to highlight a helpful answer? Upvote!
Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >
Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >
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?