3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function swap(&$arr, $i, $j) { $temp = $arr[$i]; $arr[$i] = $arr[$j]; $arr[$j] = $temp; } function quicksort(&$arr, $left, $right) { $pivot = $arr[($left + $right) >> 1]; $i = $left; $j = $right; while ($i <= $j) { while ($arr[$i] < $pivot) { $i++; } while ($arr[$j] > $pivot) { $j--; } if ($i <= $j) { swap($arr, $i++, $j--); } } if ($left < $j) { quicksort($arr, $left, $j); } if ($i < $right) { quicksort($arr, $i, $right); } } function qsort($len) { // Sample data $arr = array(); for ($i = 0 ; $i < $len ; $i++) { $arr[$i] = floor(rand(0, $len)); if ($i % 2 == 0) { $arr[$i] = -1 * $arr[$i]; } } $start = microtime(true); quicksort($arr, 0, count($arr) - 1); $diff = microtime(true) - $start; for ($i = 1 ; $i < count($arr) ; $i++) { if ($arr[$i-1] > $arr[$i]) { die("failed to sort!!"); } } return $diff; } $len = 100000; $min = PHP_INT_MAX; for ($i = 0 ; $i < 3 ; $i++) { $time = qsort($len); if ($time < $min) { $min = $time; } }
Output for 5.1.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Output for 4.4.0 - 4.4.9, 5.0.5

Process exited with code 137.
Output for 4.3.0 - 4.3.11, 5.0.0 - 5.0.4
Notice: Use of undefined constant PHP_INT_MAX - assumed 'PHP_INT_MAX' in /in/Y6HtY on line 76
Process exited with code 137.