Graphics Programs Reference
In-Depth Information
Touch and hold your finger on the
TouchTracker
screen. Move your finger around but
keep it on the screen. This sends
touchesMoved:withEvent:
over and over to the
TouchDrawView
. Each
touchesMoved:withEvent:
message causes
drawRect:
to be sent, which in turn causes the silly
sin
code to run repeatedly.
As you move your finger, watch the table in
Instruments
shuffle around its items. Then
click the pause button (to the left of the
Stop
button) and examine the table's contents.
Each row is one function or method call. In the left column, the amount of time spent in
that function (expressed in milliseconds and as a percentage of the total run time) is dis-
played (
Figure 21.17
)
. This gives you an idea of where your application is spending its ex-
ecution time.
Figure 21.17 Time Profiler results
There is no rule that says, “If X percentage of time is spent in this function, your applica-
tion has a problem.” Instead, use
Time Profiler
if you notice your application acting slug-
gish while testing it as a user. For example, you should notice that drawing in
TouchTracker
is less responsive since we added the wasteful
sin
code.
We know that when drawing a line, two things are happening:
touchesMoved:withEvent:
and
drawRect:
are being sent to the
TouchDrawView
view. In
Time Profiler
, we can check to see how much time is spent in
these two methods relative to the rest of the application. If an inordinate amount of time is
being spent in one of these methods, we know that's where the problem is.