二分查找法
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
var arr=[];
for(var i=1;i<=90000000;i++){
arr.push(i);
}
function binarySearch(arr,value){
var start=Date.now();
var startIndex=0;
var stopIndex=arr.length-1;
var middleIndex=Math.floor((startIndex+stopIndex)/2)
while(arr[middleIndex]!=value&&startIndex<stopIndex){
if(value<arr[middleIndex]){
stopIndex=middleIndex-1;
}else{
startIndex=middleIndex+1
}
middleIndex=Math.floor((startIndex+stopIndex)/2);
}
var stop=Date.now();
console.log("binarySearch tinmes"+(stop-start));
}
binarySearch(arr,9629999);
</script>
</head>
<body>
</body>
</html>