CocoaDev

Edit AllPages

I just created a very simple timer. It is just a wraper around the gettimeofday() funtion, but it make the code using it so much simpler and nice. I enjoyed writing this, and you are invited to improve this if you have any nice idea. –NirSoffer

Typical Usage:

#import “NIRTimer.h”

NIRTimer *timer = [[NIRTimer alloc] init];

[timer start]; [someObject doLongOperation]; [timer stop];

NSLog(@”doLongOperation: %6.3f seconds”, [timer seconds]);

[timer start]; [someObject doMore]; [timer stop];

NSLog(@”doMore: %6.3f seconds”, [timer secondsSinceStart]); NSLog(@”Total: %6.3f seconds”, [timer seconds]);


Here is the code:

// // NIRTimer.h // DirectionService // // Created by Nir Soffer on Wed Jun 04 2003. // Copyright (c) 2003 Nir Soffer. All rights reserved. //

#import <Foundation/Foundation.h>

@interface NIRTimer : NSObject { long started; long time; BOOL isRunning; }

// reset

// starting and stoping

// reporting total time

// reporting elapsed time - from last start

@end

// // NIRTimer.m // DirectionService // // Created by Nir Soffer on Wed Jun 04 2003. // Copyright (c) 2003 Nir Soffer. All rights reserved. //

#import “NIRTimer.h” #import <sys/time.h>

@interface NIRTimer (NIRTimerPrivate)

@implementation NIRTimer

// reset

// starting and stoping

// reporting time

// reporting elapsed time - from last start

@end

@implementation NIRTimer (NIRTimerPrivate)

@end