0 votes
1 view
in R Programming by (4.1k points)

I know that I can use system.time before and after the execution and after this take the difference of those, but I want to know any function or a standardized way.

I have tried this:

somesysfunction("myfunction(with,arguments)")

> Start time : 2001-01-01 00:00:00  # output of somesysfunction

> "Result" "of" "myfunction"        # output of myfunction

> End time : 2001-01-01 00:00:10    # output of somesysfunction

> Total Execution time : 10 seconds # output of somesysfunction

1 Answer

0 votes
by (46.1k points)

The best way is to use system.time() as described by you in the question. To make it a short function use replicate() in it:

system.time( replicate(10000, myfunction(with,arguments) ) )

Here replicate is used to repeat the process “10000” times. It’s not important to use this as it’s only used to make the code shorter.

> System.time::system.time(log10(5), log(5)/log(10), times = 10000) Unit: nanoseconds

expr               min lq mean median   uq max neval cld

log10(5) 0        0     0 25.5738   0               1 10265 10000  a

log(5)/log(10)   0    0   28.1838   0              1 10265 10000

Here both the expressions were evaluated 10000 times, with mean execution time being around 25-30 ns.

Or, install the rbenchmark package as it allows us to specify how many times to replicate the test and would the relative benchmark would be.

To install it click here.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...