On 22-12-2009, at 15:50, Sven Schreiber wrote:
Hi,
yet another useless benchmarking exercise: I was playing around a little
comparing the speed of various matrix languages with respect to doing
stochastic simulations. The codes below draw repeated random samples,
compute their means, and find the 95% percent quantile of the empirical
distribution of the means. I distinguish between a "naive" loop
programming variant and one working only with matrix functions. Here are
the results on Ubuntu Linux 9.10 (I ran the scripts/programs several
times and they are pretty robust):
I ran the test on my iMac for Octave, Gretl 1.8.6 and R 2.10.1
I used your Octave and gretl code. My R code is after the results.
Interestingly enough there isn't a lot of difference between the loop code and the
vectorized code in this case.
Berend
Results:
================================================
Mac OS X 10.6.2 iMac late 2006 Intel Core 2 Duo 2.16Ghz 3Gb memory
Length=1000
Iterations=10000
Version Loop Vectorized
Octave 3.23 3.08 0.59
Gretlcli 1.8.6.cvs 2.79 1.62
R version 2.10.1 Patched (2009-12-17 r50777)
Terminal version
------------------
Loop Vectorized
user system elapsed user system elapsed
R 32-bit 1.669 0.054 1.729 1.616 0.213 1.829
R 64-bit 1.668 0.051 1.720 1.616 0.217 1.832
R.app GUI
------------------
Loop Vectorized
user system elapsed user system elapsed
R 32-bit 2.115 0.039 2.138 1.948 0.219 2.151
R 64-bit 1.696 0.029 1.713 1.628 0.004 1.620
<R-code>
nlen <- 1000
iterations <- 10000
averages <- numeric(iterations)
whichp <- 0.95
system.time( {
for(k in 1:iterations) { v <- rnorm(nlen); averages[k] <- mean(v) }
result <- quantile(averages,probs=c(whichp))
})
print(result)
system.time({
averages2 <- colMeans(matrix(data=rnorm(nlen*iterations), nrow=nlen,
ncol=iterations))
result2 <- quantile(averages2,probs=c(whichp))
})
print(result2)
</R-code>