3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testList = [ [ 'array' => [], 'expect' => true, ], [ 'array' => ['a', 'b', 'c'], 'expect' => true, ], [ 'array' => ["0" => 'a', "1" => 'b', "2" => 'c'], 'expect' => true, ], [ 'array' => ["1" => 'a', "0" => 'b', "2" => 'c'], 'expect' => false, ], [ 'array' => ["a" => 'a', "b" => 'b', "c" => 'c'], 'expect' => false, ], ]; function displayBenchmark($function) { global $testList; echo '<h5>use function <code>' . $function . '</code></h5>'; $i = 0; $startTime = microtime(true); for ($i = 0; $i <= 1000; ++$i) { foreach ($testList as $testItem) { $result = $function($testItem['array']); assert($result === $testItem['expect'], 'Unexpect matched on index ' . $i); ++$i; } } $totalTime = microtime(true) - $startTime; echo 'total time: ' . var_export($totalTime, true) . '<br>'; } function array_is_list1(array $arr) { if ($arr === []) { return true; } return array_keys($arr) === range(0, count($arr) - 1); } function array_is_list2(array $array): bool { $i = -1; foreach ($array as $k => $v) { ++$i; if ($k !== $i) { return false; } } return true; } class Benchmark { private static $max, $memory; public static function memoryTick() { self::$memory = memory_get_usage() - self::$memory; self::$max = self::$memory>self::$max?self::$memory:self::$max; self::$memory = memory_get_usage(); } public static function benchmarkMemory(callable $function, $args=null) { declare(ticks=1); self::$memory = memory_get_usage(); self::$max = 0; register_tick_function('call_user_func_array', ['Benchmark', 'memoryTick'], []); $result = is_array($args)? call_user_func_array($function, $args): call_user_func($function); unregister_tick_function('call_user_func_array'); return [ 'memory' => self::$max ]; } } var_dump(Benchmark::benchmarkMemory('displayBenchmark', ['array_is_list'])); var_dump(Benchmark::benchmarkMemory('displayBenchmark', ['array_is_list1'])); var_dump(Benchmark::benchmarkMemory('displayBenchmark', ['array_is_list2']));
Output for git.master_jit
<h5>use function <code>array_is_list</code></h5>total time: 7.987022399902344E-5<br>array(1) { ["memory"]=> int(280) } <h5>use function <code>array_is_list1</code></h5>total time: 0.0002980232238769531<br>array(1) { ["memory"]=> int(192) } <h5>use function <code>array_is_list2</code></h5>total time: 0.00010204315185546875<br>array(1) { ["memory"]=> int(192) }
Output for git.master
<h5>use function <code>array_is_list</code></h5>total time: 9.107589721679688E-5<br>array(1) { ["memory"]=> int(280) } <h5>use function <code>array_is_list1</code></h5>total time: 0.00015306472778320312<br>array(1) { ["memory"]=> int(192) } <h5>use function <code>array_is_list2</code></h5>total time: 0.0001270771026611328<br>array(1) { ["memory"]=> int(192) }
Output for rfc.property-hooks
<h5>use function <code>array_is_list</code></h5>total time: 7.796287536621094E-5<br>array(1) { ["memory"]=> int(280) } <h5>use function <code>array_is_list1</code></h5>total time: 0.00013494491577148438<br>array(1) { ["memory"]=> int(192) } <h5>use function <code>array_is_list2</code></h5>total time: 0.00013494491577148438<br>array(1) { ["memory"]=> int(192) }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
25.06 ms | 409 KiB | 5 Q