Created
September 22, 2015 15:37
-
-
Save kaja47/b64207d1a87af43141b0 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
// size = (1 << 25), time = 800 ms | |
// size = (1 << 25) - 1999, time = 400 ms ??? | |
// size = (1 << 24), time = 700 ms | |
val size = 1 << 25 | |
val randos = new util.Random() | |
val arr = Array.fill(size)(randos.nextInt) | |
java.util.Arrays.sort(arr) | |
val queries = Array.fill(1 << 20)(randos.nextInt) | |
val s = System.nanoTime | |
var sum = 0 | |
var i = 0; while (i < queries.length) { | |
sum += java.util.Arrays.binarySearch(arr, queries(i)) | |
i += 1 | |
} | |
println((System.nanoTime - s)/1e6+" ms") | |
println(sum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment