N <- 1000000 Rprof("profile_out.txt") # one-at-a-time version draws <- matrix(NA,N,1) for (i in 0:N) { draws[i,1] <- rnorm(1) } # all at once version # draws <- rnorm(N) Rprof(NULL) summaryRprof("profile_out.txt")$by.self