The Art of R Programming

(WallPaper) #1

So,Rprof()often found that at inspection time,powers3()had called
outer(), which in turn had calledFUN(), the latter being the currently execut-
ing function. The functionsummaryRprof()conveniently summarizes all those
lines in the file, but you may find that looking at the file itself reveals more
insights in some cases.
Note, too, thatRprof()is no panacea. If the code you’re profiling pro-
duces many function calls (including indirect calls, triggered when your
code calls some function that then calls another within R), the profiling out-
put may be hard to decipher. This is arguably the case for the output from
powers4():


$by.self
self.time self.pct total.time total.pct
"apply" 19.46 67.5 27.56 95.6
"lapply" 4.02 13.9 5.68 19.7
"FUN" 2.56 8.9 2.56 8.9
"as.vector" 0.82 2.8 0.82 2.8
"t.default" 0.54 1.9 0.54 1.9
"unlist" 0.40 1.4 6.08 21.1
"!" 0.34 1.2 0.34 1.2
"is.null" 0.32 1.1 0.32 1.1
"aperm" 0.22 0.8 0.22 0.8
"matrix" 0.14 0.5 0.74 2.6
"!=" 0.02 0.1 0.02 0.1
"powers4" 0.00 0.0 28.84 100.0
"t" 0.00 0.0 28.10 97.4
"array" 0.00 0.0 0.22 0.8


$by.total
total.time total.pct self.time self.pct
"powers4" 28.84 100.0 0.00 0.0
"t" 28.10 97.4 0.00 0.0
"apply" 27.56 95.6 19.46 67.5
"unlist" 6.08 21.1 0.40 1.4
"lapply" 5.68 19.7 4.02 13.9
"FUN" 2.56 8.9 2.56 8.9
"as.vector" 0.82 2.8 0.82 2.8
"matrix" 0.74 2.6 0.14 0.5
"t.default" 0.54 1.9 0.54 1.9
"!" 0.34 1.2 0.34 1.2
"is.null" 0.32 1.1 0.32 1.1
"aperm" 0.22 0.8 0.22 0.8
"array" 0.22 0.8 0.00 0.0
"!=" 0.02 0.1 0.02 0.1


$sampling.time
[1] 28.84


Performance Enhancement: Speed and Memory 319
Free download pdf