@ 2019-05-03T00:20:46Z <?php
function BinSearch($needle, $haystack) {
$m = ceil(count($haystack) / 2);
$z = $haystack[$m];
if ($needle == $haystack[$m]) {
return "Found at index: $haystack[$needle]";
$upper = array_slice($haystack, -$m, count($haystack));
return BinSearch($needle, $upper);
} else if ($needle < $haystack[$m]) {
$lower = array_slice($haystack, 0, $m);
return BinSearch($needle, $lower);
}
}
$countries = array("Afghanistan", "Aland Islands", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Barbuda", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Trty.", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", "Caicos Islands", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Congo, Democratic Republic of the", "Cook Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories", "Futuna Islands", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard", "Herzegovina", "Holy See", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran (Islamic Republic of)", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Jan Mayen Islands", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea", "Korea (Democratic)", "Kuwait", "Kyrgyzstan", "Lao", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libyan Arab Jamahiriya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "McDonald Islands", "Mexico", "Micronesia", "Miquelon", "Moldova", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "Nevis", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Palestinian Territory, Occupied", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn", "Poland", "Portugal", "Principe", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russian Federation", "Rwanda", "Saint Barthelemy", "Saint Helena", "Saint Kitts", "Saint Lucia", "Saint Martin (French part)", "Saint Pierre", "Saint Vincent", "Samoa", "San Marino", "Sao Tome", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia", "South Sandwich Islands", "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard", "Swaziland", "Sweden", "Switzerland", "Syrian Arab Republic", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Grenadines", "Timor-Leste", "Tobago", "Togo", "Tokelau", "Tonga", "Trinidad", "Tunisia", "Turkey", "Turkmenistan", "Turks Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "US Minor Outlying Islands", "Uzbekistan", "Vanuatu", "Vatican City State", "Venezuela", "Vietnam", "Virgin Islands (British)", "Virgin Islands (US)", "Wallis", "Western Sahara", "Yemen", "Zambia", "Zimbabwe");
$country = "Pakistan";
$time_start = microtime(true);
echo BinSearch($country, $countries) . PHP_EOL;
echo 'Total execution time in seconds: ' . number_format(microtime(true) - $time_start, 20) . PHP_EOL;
$time_start = microtime(true);
array_search($country, $countries);
echo 'Total execution time in seconds: ' . number_format(microtime(true) - $time_start, 20) . PHP_EOL;
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.4.1 0.012 0.012 14.95 7.4.0 0.006 0.009 14.82 7.3.13 0.008 0.011 14.57 7.3.12 0.007 0.007 15.06 7.3.11 0.013 0.008 15.01 7.3.10 0.018 0.000 14.98 7.3.9 0.007 0.010 14.79 7.3.8 0.010 0.003 15.09 7.3.7 0.004 0.007 14.70 7.3.6 0.003 0.006 14.81 7.3.5 0.007 0.007 14.76 7.3.4 0.007 0.013 14.81 7.3.3 0.011 0.008 14.82 7.3.2 0.008 0.005 15.74 7.3.1 0.011 0.010 15.95 7.3.0 0.010 0.008 15.59 7.2.26 0.007 0.014 15.34 7.2.25 0.006 0.012 15.16 7.2.24 0.008 0.008 15.38 7.2.23 0.007 0.011 15.42 7.2.22 0.009 0.006 15.02 7.2.21 0.012 0.006 15.09 7.2.20 0.008 0.008 15.21 7.2.19 0.000 0.015 15.16 7.2.18 0.010 0.010 14.97 7.2.17 0.005 0.008 14.99 7.2.16 0.007 0.009 14.94 7.2.15 0.010 0.012 16.17 7.2.14 0.014 0.011 15.99 7.2.13 0.003 0.013 16.00 7.2.12 0.013 0.003 16.15 7.2.11 0.006 0.012 15.91 7.2.10 0.010 0.009 16.06 7.2.9 0.008 0.010 15.85 7.2.8 0.014 0.007 15.99 7.2.7 0.008 0.006 16.19 7.2.6 0.008 0.010 16.01 7.2.5 0.014 0.008 16.11 7.2.4 0.016 0.003 15.98 7.2.3 0.013 0.008 16.20 7.2.2 0.011 0.007 15.96 7.2.1 0.010 0.010 15.87 7.2.0 0.007 0.009 15.96 7.1.33 0.004 0.015 15.83 7.1.32 0.009 0.006 15.75 7.1.31 0.009 0.006 15.94 7.1.30 0.007 0.010 15.84 7.1.29 0.000 0.016 15.83 7.1.28 0.008 0.012 14.88 7.1.27 0.013 0.005 14.86 7.1.26 0.009 0.013 14.87 7.1.25 0.015 0.008 14.93 7.1.24 0.006 0.008 15.84 7.1.23 0.007 0.007 15.83 7.1.22 0.000 0.011 15.75 7.1.21 0.000 0.017 15.62 7.1.20 0.004 0.008 15.70 7.1.19 0.009 0.003 15.71 7.1.18 0.003 0.010 15.95 7.1.17 0.007 0.010 15.98 7.1.16 0.011 0.000 15.77 7.1.15 0.004 0.009 15.76 7.1.14 0.004 0.008 15.91 7.1.13 0.007 0.007 15.71 7.1.12 0.003 0.010 15.45 7.1.11 0.003 0.007 15.93 7.1.10 0.004 0.007 15.95 7.1.9 0.004 0.011 15.98 7.1.8 0.004 0.011 15.55 7.1.7 0.006 0.006 15.70 7.1.6 0.003 0.010 15.86 7.1.5 0.006 0.003 15.80 7.1.4 0.007 0.004 15.89 7.1.3 0.008 0.004 15.83 7.1.2 0.006 0.008 15.96 7.1.1 0.009 0.006 15.68 7.1.0 0.008 0.006 16.00
preferences:dark mode live preview
31.85 ms | 401 KiB | 5 Q