views:

746

answers:

2

Where is the TickCount() call? I have seen several threads on the web that recommend using the TickCount() call for iphone development. What do i need to "#include" to use this call? What framework is it in?

If not TickCount() what should I use to get milliseconds elapsed since the cpu started?

+2  A: 

CFAbsoluteTimeGetCurrent is probably what You are looking for. (Edit: …Or maybe not. Do You really need the time from CPU start, or do You just want to measure time in ms?)

zoul
Thanks! No I do not really need the time from CPU start, just need elapsed time in MS.
Jamey McElveen
Yep, then this function is exactly it. It returns CFAbsoluteTime, which is a double in disguise. If you type your variable CFAbsoluteTime instead of double, Xcode will decorate the number as time value when showing the value bubble in debugger.
zoul
+2  A: 

In my header file, I add the following:

#include <time.h>

@interface myAppDelegate : NSObject <UIApplicationDelegate> {
  ...
  clock_t initStart, initStop;
}

In my implementation file, I add the following:

- (void) applicationDidFinishLaunching:(UIApplication *)application {
  srandom(time(NULL));
  initStart = clock();
  ...
}

...

- (void) applicationWillTerminate:(UIApplication *)application {
  initStop = clock();
  NSLog(@"Elapsed CPU time: %f", (double)(initStop - initStart) / CLOCKS_PER_SEC);
  ...
}

You could move these calls around your app as needed, to measure elapsed time.

Alex Reynolds
Thank you! Only reason I am gonna use CFAbsoluteTimeGetCurrent is that Apple used CFAbsoluteTimeGetCurrent in their GLPaint example.
Jamey McElveen