如何测量 iOS 线程的实际 CPU 时间?
我正在寻找 Android 的 iOS 模拟 SystemClock.currentThreadTimeMillis () 或 Microsoft 的 GetThreadTimes() 或Posix clock_gettime(CLOCK_THREAD_CPUTIME_ID, ) 和 pthread_getcpuclockid() 函数用于测量多线程中函数使用的实际“干净”时间 应用。也就是说,我不想测量函数中花费的实际挂钟时间,而是测量 CPU 上的时间。
我在 这里在 stackoverflow 和 其他地方。不幸的是,这两种情况都不适用于 iOS。
iOS 上有类似的功能吗?
I am looking for an iOS analog for Android's SystemClock.currentThreadTimeMillis() or Microsoft's GetThreadTimes() or Posix clock_gettime(CLOCK_THREAD_CPUTIME_ID, ) and pthread_getcpuclockid() functions to measure the actual "clean" time used by a function in a multithreaded application. That is, I don't want to measure the actual wall clock time spent in a function, but the on-CPU time.
I found interesting discussions about this here on stackoverflow and elsewhere. Unfortunately, neither applies to iOS.
Is there a comparable function for this on iOS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果有人正在寻找一个好的答案:
不久前,我在这个答案中发现了一些很棒的代码(用于查找CPU时间/OSX 中的内存使用情况),并稍作调整。我用它来对 ARM 上的一些 NEON 优化进行基准测试。您可能只需要为当前线程获取时间的部分。
In case anyone is looking for a good answer:
A while ago I found some great code in this answer (for finding CPU time/memory usage in OSX), and adapted it slightly. I used this for benchmarking some NEON optimizations on the ARM. You would probably only need the section which gets time for the current thread.
我使用这段代码来测量线程 CPU 时间。它基于 tcovo 的答案,但更加简洁和集中。
thread_time.h
thread_time.c
I use this code to measure thread CPU time. It's based on tcovo's answer, but is more concise and focused.
thread_time.h
thread_time.c
从它的描述来看,clock()函数似乎可以满足您的需要?
http://developer.apple。 com/library/ios/#documentation/System/Conceptual/ManPages_iPhoneOS/man3/clock.3.html
From its description it seems that the clock() function does what you need?
http://developer.apple.com/library/ios/#documentation/System/Conceptual/ManPages_iPhoneOS/man3/clock.3.html