Created
December 21, 2013 15:44
-
-
Save allenhwkim/8071013 to your computer and use it in GitHub Desktop.
The fastest search ever for large amount of data http://jsperf.com/binary-search-1234
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
function search(arr, o) { | |
var l = 0, | |
u = arr.length, | |
m; | |
while (l <= u) { | |
if (o > arr[(m = ((l + u) >> 1))]) | |
l = m + 1; | |
else | |
u = (o == arr[m]) ? -2 : m - 1; | |
} | |
return (u == -2) ? m : -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment