On 23-12-2009, at 20:34, Berend Hasselman wrote:
I did some more tests with R. I have only tested R.app 32 bit.
The R script of my previous post was much too long and had a mistake in adding a row to
the data.frame (mixing character and numeric data in a vector). I have also added the
quantile value to the table to check (column result).
The result for the corrected script is (still using R.app 32-bit)
RNGmethod ctype result user system elapsed
1 Inversion loop 0.05180068 1.681 0.006 1.687
2 Inversion iteration 0.05211462 1.648 0.206 1.853
3 Kinderman-Ramage loop 0.05228179 1.105 0.061 1.166
4 Kinderman-Ramage iteration 0.05176681 1.027 0.001 1.028
5 Box-Muller loop 0.05224984 1.513 0.018 1.531
6 Box-Muller iteration 0.05208642 1.417 0.005 1.423
7 Ahrens-Dieter loop 0.05237948 1.076 0.021 1.097
8 Ahrens-Dieter iteration 0.05192184 0.993 0.000 0.993
The Ahrens-Dieter method is still the quickest.
Berend
<R-code>
resdata <- data.frame(RNGmethod="",ctype="", result=0, user=0,
system=0, elapsed=0,stringsAsFactors=FALSE,row.names=NULL)
nlen <- 1000
iterations <- 10000
averages <- numeric(iterations)
whichp <- 0.95
for( Rmethod in c("Inversion","Kinderman-Ramage",
"Box-Muller", "Ahrens-Dieter") ) {
RNGkind(normal.kind=Rmethod)
t <- system.time( {
for(k in 1:iterations) { v <- rnorm(nlen); averages[k] <- mean(v) }
result <- quantile(averages,probs=c(whichp))
})
resdata <- rbind(resdata, list(RNGmethod=Rmethod, ctype="loop",
result=result, user=t[1],system=t[2],elapsed=t[3]))
t <- system.time({
averages2 <- colMeans(matrix(data=rnorm(nlen*iterations), nrow=nlen,
ncol=iterations))
result <- quantile(averages2,probs=c(whichp))
})
resdata <- rbind(resdata, list(RNGmethod=Rmethod, ctype="iteration",
result=result, user=t[1],system=t[2],elapsed=t[3]))
}
# delete dummy first row
resdata <- resdata[2:nrow(resdata),]
row.names(resdata) <- NULL
resdata
</R-code>