Skip to content

Instantly share code, notes, and snippets.

@kaja47
Created September 22, 2015 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaja47/b64207d1a87af43141b0 to your computer and use it in GitHub Desktop.
Save kaja47/b64207d1a87af43141b0 to your computer and use it in GitHub Desktop.
// 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