-
-
Save presidentbeef/b9a7e754a5b5e7a9018f to your computer and use it in GitHub Desktop.
Brat code (with LuaJIT) beats Ruby code (implemented in C) for first time evar?
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
In place shuffle of 1,000,000 item array over 10 runs. Brat code "precompiled" to Lua. | |
Brat | Ruby | |
------|------ | |
Best .033s | .048s | |
Median .043s | .049s | |
Worst .046s | .052s |
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
#* http://rosettacode.org/wiki/Knuth_shuffle | |
Shuffle an array (in-place) | |
*# | |
shuffle = { a | | |
(a.length - 1).to 1 { i | | |
random_index = random(0, i) | |
temp = a[i] | |
a[i] = a[random_index] | |
a[random_index] = temp | |
} | |
a | |
} | |
shuffle 1000000.of 1 |
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
# Fastest way to make a big array? | |
Array.new(1000000, 1).shuffle! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment