@ 2019-05-03T00:48:14Z <?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;
$time_start = microtime(true);
foreach ($countries as $current) {
if ($current == $country) {
break;
}
}
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.3.5 0.010 0.011 14.53 7.3.4 0.003 0.008 14.79 7.3.3 0.012 0.000 14.63 7.3.2 0.009 0.009 14.91 7.3.1 0.018 0.009 15.00 7.3.0 0.010 0.014 14.80 7.2.18 0.009 0.009 15.09 7.2.17 0.014 0.007 14.82 7.2.16 0.009 0.016 15.06 7.2.15 0.015 0.003 15.00 7.2.14 0.008 0.006 15.11 7.2.13 0.006 0.011 15.18 7.2.12 0.014 0.010 14.97 7.2.11 0.016 0.000 15.38 7.2.10 0.015 0.009 15.21 7.2.9 0.015 0.004 15.19 7.2.8 0.003 0.011 15.05 7.2.7 0.015 0.007 14.80 7.2.6 0.015 0.009 15.27 7.2.5 0.018 0.006 14.86 7.2.4 0.018 0.012 15.05 7.2.3 0.014 0.010 15.23 7.2.2 0.013 0.009 15.01 7.2.1 0.009 0.013 15.37 7.2.0 0.016 0.011 15.01 7.1.28 0.015 0.009 13.76 7.1.27 0.008 0.008 13.90 7.1.26 0.007 0.010 14.09 7.1.25 0.011 0.014 14.04
preferences:dark mode live preview
37.83 ms | 400 KiB | 5 Q