测量库调用和回调之间的时间
你好:在 iPhone 应用程序中,我使用一个库(C++),它在计算完成时异步进行回调。 现在我想测量在进行回调之前所花费的时间(包括调用库的方法)。是否有可能使用 Apple 的 Instruments 应用程序来做到这一点?最佳实践是什么?
Hi: In an iPhone application I use a library(C++) which asynchronously makes a callback when computation is finished.
Now I want to measure the time which is spent -including the method which calls the library- until the callback is made. Are there any possibilities to do this with the Instruments application from Apple? What are the best practices?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
过去,我使用以下方法进行网络调用,我必须对其进行优化 - 尽管乍一看似乎有点复杂,但它确实给出了我所见过的最准确的时间。
In the past I have used the following for making network calls I had to optimize - although at first it seems a bit convoluted, it certainly gives the most accurate times I have seen.
我编写了一个 C++ 类来包装 mach_absolute_time 调用。这使得在事件开始/停止时添加代码以测量时间差变得很方便。
如果您想在类中使用它来进行计时(在调用之间)或基于状态的行为(在计时器达到 X 后执行某些操作),它也可以很好地工作。
StopWatch.h
StopWatch.cpp
I have written a c++ class to wrap the mach_absolute_time calls. This makes it handy to sprinkle in the code at the start/stop of events for measuring time difference.
It also works well if you want to use it in a class to do timing (between calls) or for state based behavior (do something after the timer reaches X).
StopWatch.h
StopWatch.cpp