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.