Rprof()
Rprof("profile.out")
Rprof(NULL)
> summaryRprof("method1.out")
$by.self
self.time self.pct total.time total.pct
"strsplit" 4.08 94.0 4.10 94.5
"+" 0.12 2.8 0.12 2.8
"is.character" 0.12 2.8 0.12 2.8
"as.logical" 0.02 0.5 0.02 0.5
$by.total
total.time total.pct self.time self.pct
"strsplit" 4.10 94.5 4.08 94.0
"+" 0.12 2.8 0.12 2.8
"is.character" 0.12 2.8 0.12 2.8
"as.logical" 0.02 0.5 0.02 0.5
proftools
plotProfileCallGraph("profile.out")
profr
out <- profr(code_to_profile)
> head(out)
f level time start end leaf source
8 example 1 0.44 0.00 0.44 FALSE utils
9 <Anonymous> 2 0.04 0.00 0.04 FALSE <NA>
10 library 2 0.02 0.04 0.06 FALSE base
11 source 2 0.38 0.06 0.44 FALSE base
12 prepare_Rd 3 0.04 0.00 0.04 FALSE <NA>
13 %in% 3 0.02 0.04 0.06 FALSE base
> summary(out)
f level time start
match : 7 Min. : 1.000 Min. :0.02 Min. :0.0000
%in% : 6 1st Qu.: 5.000 1st Qu.:0.02 1st Qu.:0.1200
is.factor : 6 Median : 7.000 Median :0.02 Median :0.1600
eval.with.vis: 6 Mean : 8.113 Mean :0.04 Mean :0.1685
inherits : 5 3rd Qu.:10.500 3rd Qu.:0.02 3rd Qu.:0.2200
<Anonymous> : 3 Max. :19.000 Max. :0.44 Max. :0.4200
(Other) :82
end leaf source
Min. :0.0200 Mode :logical Length:115
1st Qu.:0.1400 FALSE:99 Class :character
Median :0.2000 TRUE :16 Mode :character
Mean :0.2085 NA's :0
3rd Qu.:0.2500
Max. :0.4400
Here I should say that `code_to_profile` was the standard `example(glm)`. One can also use `plot()` or `ggplot()` to plot the ‘call tree’. I’m not quite sure what a ‘call tree’ is, and to be honest the (adimittedly pretty) graph that `ggplot(out)` produces doesn’t enlighten me a great deal. That’s OK though – all I really wanted was the time spent.
A quick point about Hadley’s code, that I think highlights something wrong with R in general (and right with Python) is that in `profr`, from a user perspective I don’t really have to learn anything new to make it work. I apply a function (handily called `profr`) to some code and I get back a `data.frame` on which I can use very standard tools in order to investigate. I don’t have to write to a file (or generate a temp file to write to or anything), I don’t have to learn to stop and start hidden things, or that to stop profiling I pass `NULL` to a function that started profiling. I don’t have to use a whole new tool to parse what is basically a table. And to plot I can just use `plot` rather than having to dissapear down the (admittedly fun) hole that is graphviz. It feels like every new thing I come across in R means learning a whole API and set of concepts and object structure. (Admittedly ggplot is the total opposite of this, but hey I guess that was the point)
Image may be NSFW.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
Clik here to view.
