[R] Displaying RProf output

hadley wickham h.wickham at gmail.com
Sun Sep 4 19:05:23 CEST 2005


Hi,

I've been experimenting with a new way of displaying the output from
RProf, to make it easier to optimise your functions.  I've included an
example below.  I'd love to get your feedback on how easy you think
this graphic is to read, and on ways that it could be improved.

install.packages("butler")
library(butler)

# profile the glm example
profile_glm <- stopwatch(function() example(glm))

# Plot the profile
# y-axis gives percent of time spent in that function
# x-axis gives position in call stack
plot(profile_glm)

# The first few levels aren't of interest, so we can skip them:
# (see ?plot.call.tree for all options)
plot(profile_glm, startlevel=4)

# We might also want to see what's going further down
plot(profile_glm, startlevel=4, depth=10)

# By default only functions that take longer than 2% of the 
# total time are shown, setting mintime changes that
plot(profile_glm, startlevel=4, depth=10, mintime=1)

One interesting thing you can see from this example is that almost 30%
of the total time is just spent printing the output - why is it so
slow?  Well, it looks like print.summary.glm calculates a lot of the
summary statistics.

Thanks,

Hadley




More information about the R-help mailing list