Sunday, May 1, 2011

Where is the TickCount() call?

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?

From stackoverflow
  • 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?)

    Jamey McElveen : Thanks! No I do not really need the time from CPU start, just need elapsed time in MS.
    zoul : 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.
  • 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.

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

0 comments:

Post a Comment