Is there an objective-c/iPhone version of currentTimeMillis() from Java?

前端 未结 5 1864
广开言路
广开言路 2021-02-19 03:57

I need to time some events in the app I\'m working on. In Java i used to be able to call currentTimeMillis() but there doesnt seem to be a version in Objective-c. Is there a way

5条回答
  •  眼角桃花
    2021-02-19 04:35

    Instead gettimeofday() you could also use [NSDate timeIntervalSinceReferenceDate] (the class method) and do your calculations with that. But they have the same problem: they operate on "wall clock time". That means your measurement can be off if leap seconds are added while your test is running or at the transition between daylight saving time.

    You can use the Mach system call mach_absolute_time() on OS X and iOS. With the information returned by mach_timebase_info() this can be converted to nanoseconds.

提交回复
热议问题