Accurate Timer

Discussion in 'Mac Programming' started by cpsmusic, Oct 26, 2008.

  1. cpsmusic macrumors newbie

    Joined:
    Feb 24, 2008
    #1
    I'm porting a Windows app that uses the Performance Counter for some timing measurements. It's important that the measurements are as accurate as possible.

    Is there an accurate timer available on the Mac? If so, where can I find info about it?

    Cheers,

    Chris
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
  3. cpsmusic thread starter macrumors newbie

    Joined:
    Feb 24, 2008
    #3
    Thanks for the info.

    I don't think those timers will be accurate enough.

    Also, I'm using C++ (sorry, forgot to mention that before).

    Cheers,

    Chris
     
  4. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #4
    mach_absolute_time gives nanosecond precision in 10.2 and later.
     
  5. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #5
    as an aside, in the abscence of a real-time OS whose scheduler can guarantee a process CPU time with very strict constraints, this is all for naught. Your process could be preempted immediately after any call giving you some sort of nanosecond precise timing. By the time your next instruction runs, the sampling, timer value, etc. may be woefully and misleadingly out of date. I don't wish to discourage your efforts, only get you thinking and temper your expectations.

    -Lee
     
  6. cpsmusic thread starter macrumors newbie

    Joined:
    Feb 24, 2008
    #6
    Thanks, mach_absolute_time is what I'm looking for.

    I also realise that this timer can be inaccurate.

    Cheers,

    Chris
     

Share This Page