Measuring iPhone performance for code that only runs once?

I would like to measure the performance of code on an iPhone that only runs once, so the tool analyzer tool is of limited use since it takes many iterations to collect enough samples.

Is there a tool that I can use every time every function for every call? Does this trigger tracing instead of statistical sampling?

Regards, Jochen

+2


source to share


4 answers


Question "Are there no sampling time profiling tools for iPhone applications?" is similar to what you are asking. In my answer, I point out DTrace, which can do feature-based profiling, but unfortunately only works in the simulator, not the device itself. You can also collect data with Shark with a small sampling interval.

Finally, code like the one below can be used to execute runtime code in your application:



CFAbsoluteTime elapsedTime, startTime = CFAbsoluteTimeGetCurrent();

// Your code here

elapsedTime = CFAbsoluteTimeGetCurrent() - startTime;
NSLog(@"Elapsed time in seconds: %f", elapsedTime);

      

+8


source


If you have a large block of code that unacceptably does one time when it is called, the odds are pretty good, as it has some time-consuming loops in it, or you have calls for inefficient lower-level functions. Loop control structures should be easy to fit in the test, and identifying low-level ineffective functions is usually fairly straightforward using CGAbsoluteTimeGetCurrent () and "debug binary search" (is the bottleneck in the first half of the block or the second? First quarter or second quarter ? etc.)

If you cannot find a hotspot with this type of search, this is a pretty good sign that you are doing okay, in terms of performance and better performance, it will take some rethinking of your approach.



I don't mean to be funny, but are you sure you don't care? If the code is executed only once, the relative performance can be a matter of curiosity of more than value to the end user.

+2


source


This can be done with interposing, here is an article introducing how this can be done to track messages, you could adapt their execution times.

0


source


Recently, the Pulse development team published an article on how to measure the performance of single lines (or more) of Objective-c code: http://eng.pulse.me/line-by-line-speed-analysis-for-ios-apps/

0


source







All Articles