I am trying to measure the computation time of a function in R using system.time()
.
I want to run the function a few hundred times to get an average but I don\'t w
You want to use the rbenchmark package and its function benchmark()
which does just about everything for you.
Here is the first example from its help page:
R> example(benchmark)
bnchmrR> # example 1
bnchmrR> # benchmark the allocation of one 10^6-element numeric vector,
bnchmrR> # replicated 100 times
bnchmrR> benchmark(1:10^6)
test replications elapsed relative user.self sys.self user.child sys.child
1 1:10^6 100 0.327 1 0.33 0 0 0
For truly expression-level benchmarking, there is also the microbenchmark package.