I did some more tests with R. I have only tested R.app 32 bit.
R has several methods for generating random numbers from a normal distribution.
Caveat: I have no idea what the different methods actually do.
The Ahrens-Dieter method appears to be the fastest.
Results:
RNGmethod ctype user system elapsed
1 Inversion loop 1.676 0.013 1.713
2 Inversion iteration 1.626 0.213 1.842
3 Kinderman-Ramage loop 1.101 0.05 1.155
4 Kinderman-Ramage iteration 1.012 0.002 1.013
5 Box-Muller loop 1.509 0.021 1.532
6 Box-Muller iteration 1.419 0.007 1.428
7 Ahrens-Dieter loop 1.08 0.035 1.115
8 Ahrens-Dieter iteration 0.992 0.001 0.995
Berend
<R-code>
resdata <- data.frame(RNGmethod="",ctype="", user=0, system=0,
elapsed=0,stringsAsFactors=FALSE,row.names=NULL)
nlen <- 1000
iterations <- 10000
averages <- numeric(iterations)
whichp <- 0.95
Rmethod="Inversion"
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, c(RNGmethod=Rmethod, ctype="loop",
user=t[1],system=t[2],elapsed=t[3]))
t <- system.time({
averages2 <- colMeans(matrix(data=rnorm(nlen*iterations), nrow=nlen,
ncol=iterations))
result2 <- quantile(averages2,probs=c(whichp))
})
resdata <- rbind(resdata, c(RNGmethod=Rmethod, ctype="iteration",
user=t[1],system=t[2],elapsed=t[3]))
Rmethod="Kinderman-Ramage"
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, c(RNGmethod=Rmethod, ctype="loop",
user=t[1],system=t[2],elapsed=t[3]))
t <- system.time({
averages2 <- colMeans(matrix(data=rnorm(nlen*iterations), nrow=nlen,
ncol=iterations))
result2 <- quantile(averages2,probs=c(whichp))
})
resdata <- rbind(resdata, c(RNGmethod=Rmethod, ctype="iteration",
user=t[1],system=t[2],elapsed=t[3]))
Rmethod="Box-Muller"
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, c(RNGmethod=Rmethod, ctype="loop",
user=t[1],system=t[2],elapsed=t[3]))
t <- system.time({
averages2 <- colMeans(matrix(data=rnorm(nlen*iterations), nrow=nlen,
ncol=iterations))
result2 <- quantile(averages2,probs=c(whichp))
})
resdata <- rbind(resdata, c(RNGmethod=Rmethod, ctype="iteration",
user=t[1],system=t[2],elapsed=t[3]))
Rmethod="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, c(RNGmethod=Rmethod, ctype="loop",
user=t[1],system=t[2],elapsed=t[3]))
t <- system.time({
averages2 <- colMeans(matrix(data=rnorm(nlen*iterations), nrow=nlen,
ncol=iterations))
result2 <- quantile(averages2,probs=c(whichp))
})
resdata <- rbind(resdata, c(RNGmethod=Rmethod, ctype="iteration",
user=t[1],system=t[2],elapsed=t[3]))
# delete dummy first row
resdata <- resdata[2:nrow(resdata),]
row.names(resdata) <- NULL
print(resdata, digits=4)
</R-code>