Cocoa 中测量时间的方法
1. The Methods to Get Current Timestamp
iOS中获取时间戳的方法:
A. CACurrentMediaTime()
B. gettimeofday
C. CFAbsoluteTimeGetCurrent
D. [NSDate date] timeIntervalSince1970]
E. mach_absolute_time()
Ref[1]对比了以上方法的耗时,但是其准确性需要验证。
2. Clock Time
时钟时间
"CFAbsoluteTimeGetCurrent [NSDate timeIntervalSinceReferenceDate] return clock time.
Clock time is synchronized with the network time signal. So, they are not suitable for timestamp." Ref[2]
3. 各种方法的对比以及适用场景
3.1 对于测量App中某些操作的所消耗的时间,用CACurrentMediaTime()来说很合适。
Reference
1. http://*.com/questions/358207/iphone-how-to-get-current-milliseconds
2. Tip: CACurrentMediaTime
http://www.alexcurylo.com/blog/2009/09/05/tip-cacurrentmediatime/
4. Benchmarking
http://nshipster.com/benchmarking/
http://nshipster.cn/benchmarking/
http://bendodson.com/weblog/2013/01/29/ca-current-media-time/
Todo
1. Timers, Clocks, and Cocoa
http://devetc.org/code/2014/01/21/timers-clocks-and-cocoa.html
2.
http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=1019
3. All in the Timing: Keeping Track of Time Passed on iOS
http://blog.spacemanlabs.com/2011/09/all-in-the-timing-keeping-track-of-time-passed-on-ios/
4. How to convert mach_absolute_time() into seconds?