Created
September 9, 2015 21:40
-
-
Save nkurz/8fa6ff3772a054294531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### compare times for sample.int() vs internal function sample2() | |
compareSampleTimes = function(popSizeList=c(1e5, 1e6, 1e7, 1e8, 1e9), | |
sampleSizeList=c(10, 100, 1000, 10000), | |
numReplications=1000) { | |
for (sampleSize in sampleSizeList) { | |
for (popSize in popSizeList) { | |
elapsed1 = system.time(replicate(numReplications, sample.int(popSize, sampleSize)))[["elapsed"]] | |
elapsed2 = system.time(replicate(numReplications, .Internal(sample2(popSize, sampleSize))))[["elapsed"]] | |
cat(sprintf("Sample %d from %.0e: %f vs %f seconds\n", sampleSize, popSize, elapsed1, elapsed2)) | |
} | |
cat("\n") | |
} | |
} | |
compareSampleTimes() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment