I am trying to understand why this bit of code (adapted from R Benchmark 2.5 ) becomes slower and slower (on average) as the number of iterations increases.
require(Matrix) c <- 0; for (i in 1:100) { a <- new("dgeMatrix", x = rnorm(3250 * 3250), Dim = as.integer(c(3250, 3250))) b <- as.double(1:3250) invisible(gc()) timing <- system.time({ c <- solve(crossprod(a), crossprod(a, b)) }) print(timing) rm(a, b, c) }
Here is an example of a sample that is slightly different from one run to the next.
As I understand it, nothing should be saved from one iteration to another, but time slowly increases from 1 second in the first few cycles to more than 4 seconds in subsequent cycles. Do you have any ideas what causes this, and how can I fix it?
Switching the for loop into the application * seems to give similar results.
I know that the code is not optimized, but it comes from a widely used test, and depending on what causes this behavior, it may indicate a serious bias in its results (which by default only runs three times).
I am running R version 3.0.1 (x86_64) on Mac OS 10.8.4 with 16 GB of RAM (many of them are free). BLAS is OpenBLAS.
performance benchmarking r blas
RenΓ©r
source share