Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the runtime of an R script?

Tags:

r

runtime

I am running a single script in R using source('scriptname.R').

I would like to get the running time of this script.

Can someone advise me on how I can do this?

like image 319
Kt Mack Avatar asked Oct 26 '13 23:10

Kt Mack


People also ask

How do I get the runtime of a code in R?

To measure execution time of R code, we can use Sys. time function. Put it before and after the code and take difference of it to get the execution time of code.

How do I know if an R script is running?

In RStudio, select "New Script" from the "File" menu. You'll now see a "Script" panel appear. Try typing a command into this panel and then press the "Run" button shown below. You should see the results of running the script appear in the console panel.

How long does R take to run?

It takes 4-6 weeks to learn R without programming knowledge.

How do you define a function in R?

In R, a function is an object so the R interpreter is able to pass control to the function, along with arguments that may be necessary for the function to accomplish the actions. The function in turn performs its task and returns control to the interpreter as well as any result which may be stored in other objects.


2 Answers

tl;dr: Wrap system.time(source("scriptname.R")) around it.

Longer answer: Read the "Writing R Extensions" manual about profiling your code, and look at a few of the profiling packages which help aggregate the raw profiling data. The newest, and possibly nicest is Hadley's lineprof package on github.

like image 92
Dirk Eddelbuettel Avatar answered Nov 14 '22 23:11

Dirk Eddelbuettel


system.time should do:

system.time(source('scriptname.R'))
like image 29
Konrad Rudolph Avatar answered Nov 15 '22 01:11

Konrad Rudolph