How to Time Profile

How to Time Profile

- 3 mins

Xcode Instrument: Time Profiler

Astounding effects of Xcode instruments has been discussed earlier also. Nevertheless to say, a huge share of iOS applications benefited from it.

TL;DR

Time profiler is an important instrument which helps in achieving better performance in iOS applications. It provides details about time consumed by each method in your source code, giving able space to alter the logic applied. Developers can use this cluster of information to redefine the existing algorithms.

Kick Start: Time Profiler in Developer world

Open your source code in Xcode and go to Product and select Profile to start Profiling with Instruments, You can use shortcut key Command + I to do the same. Once building is complete, you will see Instruments Box to select from, as shown below:

This opens up our host of the night, Time profiler. Now click on Record button on top right corner to start profiling.

Once you run through your application during the recording session, profiler will start capturing the method signatures. On completion, click on Stop button and you can observe the details in details panel.

Terms that you see in detail panel

Let us see, how we can alter the logic by using Time Profiler in actual application. Here we will compare with a simple for loop and while loop case to identify which one actually executes faster. We are not considering the resource usage in this example.

One with For loop:

One with While loop:

Post running Profiler, we can see the results as shown below:

Filters used in Call tree to obtain above results were.

To infer from image, while loop took around 7.00ms and for loop as 6.00ms. We would now select the for loop as it works great.

FYI, this is just an example to show the time constraints what we actually need to look for. If you consider about resource allocations and memory used, Time profiler cannot be a helpful tool to analyse it.

Example Time Profiler GitHub code can be seen HERE

It is obvious that a good iOS coder, will always profile with Time profiler to make sure application works best for them.

Good luck all.

If you would like to read more on the Launch time and tricks, do read my Medium story HERE

Bittu Davis

Bittu Davis

an iOS Enthusiast | an Open Book

comments powered by Disqus
rss facebook twitter github gitlab youtube mail spotify lastfm instagram linkedin google google-plus pinterest medium vimeo stackoverflow reddit quora quora