3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function benchmark($n) { $iterations = intval(1000000 / $n); print "$iterations iterations, $n range\n"; $a = range(0, $n); $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) (array) $a !== $a; $trick = microtime(TRUE) - $start; $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) !is_array($a); $is_array = microtime(TRUE) - $start; print '(array) !== is ' . ($trick < $is_array ? 'faster' : 'slower') ." than !is_array() for arrays and $n\n"; $a = range(0, $n); $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) (array) $a === $a; $trick = microtime(TRUE) - $start; $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) is_array($a); $is_array = microtime(TRUE) - $start; print '(array) === is ' . ($trick < $is_array ? 'faster' : 'slower') ." than is_array() for arrays and $n\n"; $a = (object) range(0, $n); $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) (array) $a !== $a; $trick = microtime(TRUE) - $start; $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) !is_array($a); $is_array = microtime(TRUE) - $start; print '(array) !== is ' . ($trick < $is_array ? 'faster' : 'slower') ." than !is_array() for object and $n\n"; $a = (object) range(0, $n); $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) (array) $a === $a; $trick = microtime(TRUE) - $start; $start = microtime(TRUE); for ($i = 1; $i < $iterations; $i++) is_array($a); $is_array = microtime(TRUE) - $start; print '(array) === is ' . ($trick < $is_array ? 'faster' : 'slower') ." than is_array() for objects and $n\n"; } benchmark(10); print "\n"; benchmark(140); print "\n"; benchmark(150); print "\n";
Output for 4.3.0 - 7.1.0
100000 iterations, 10 range (array) !== is slower than !is_array() for arrays and 10 (array) === is slower than is_array() for arrays and 10 (array) !== is slower than !is_array() for object and 10 (array) === is slower than is_array() for objects and 10 7142 iterations, 140 range (array) !== is slower than !is_array() for arrays and 140 (array) === is slower than is_array() for arrays and 140 (array) !== is slower than !is_array() for object and 140 (array) === is slower than is_array() for objects and 140 6666 iterations, 150 range (array) !== is slower than !is_array() for arrays and 150 (array) === is slower than is_array() for arrays and 150 (array) !== is slower than !is_array() for object and 150 (array) === is slower than is_array() for objects and 150