Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to print start time, end time and total execution in R, and append a label to it

Tags:

r

old <- Sys.time()

// MY code

new <- Sys.time()

total time = old-new the output comes "Time difference of -6.661923 secs"

instead i want "Execution time : 0.35secs"

like image 566
Pandsh Avatar asked Nov 27 '25 03:11

Pandsh


1 Answers

You can use sprintf as below:

old <- Sys.time()
rnorm(500,0,1)
new <- Sys.time()
x <- (new - old)

sprintf("The execution time is %5.2f secs",x)

Output:

[1] "The execution time is  1.08 secs"
like image 181
PKumar Avatar answered Nov 28 '25 17:11

PKumar