[R] R Profiling

jim holtman jholtman at gmail.com
Tue Oct 12 14:15:05 CEST 2010


You can use 'system.time' to determine the elapsed and CPU time used.
Here is an example of repeating a script 10 times:

> replicate(10, system.time({
+     for (i in 1:10000) x < runif(1)
+ }))
           [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
user.self  0.09 0.06 0.07 0.06 0.08 0.07 0.06 0.06 0.06  0.06
sys.self   0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00  0.00
elapsed    0.09 0.06 0.06 0.06 0.08 0.06 0.06 0.07 0.06  0.06
user.child   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
sys.child    NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
>
> timingResult <- replicate(10, system.time({
+     # this would be where your script goes
+     for (i in 1:100000) x < runif(1)
+ }))
>
> timingResult
           [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
user.self  0.67 0.68 0.67 0.69 0.67 0.69 0.66 0.69 0.68  0.66
sys.self   0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00  0.00
elapsed    0.67 0.67 0.67 0.69 0.67 0.69 0.65 0.69 0.71  0.67
user.child   NA   NA   NA   NA   NA   NA   NA   NA   NA    NA
sys.child    NA   NA   NA   NA   NA   NA   NA   NA   NA    NA


On Tue, Oct 12, 2010 at 7:04 AM, Lorenzo Isella
<lorenzo.isella at gmail.com> wrote:
> Dear All,
> I need to do some very basic R profiling, something along the lines of: run
> this whole script five times and return the average completion time.
> I do not want (at this stage) delve into the details of the percentage of
> the time spent in which function and doing what.
> Which tools should I use?
> Any recommendation is welcome.
> Best Regards
>
> Lorenzo
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?



More information about the R-help mailing list