3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array('test1', 'test2', 'test3', 'test4'); $var = 'test'; $iterations = 1000000; $start = microtime(true); for($i = 0; $i < $iterations; ++$i) { if ($var != 'test1' && $var != 'test2' && $var != 'test3' && $var != 'test4') {} } $end = microtime(true); print "multiple comparisons: \n". ($end - $start)."\n"; $start2 = microtime(true); for($i = 0; $i < $iterations; ++$i) { if (!in_array($var, $array) ) {} } $end2 = microtime(true); print "in_array: \n".($end2 - $start2)."\n"; $start = microtime(true); $array_flip = array_flip($array); for($i = 0; $i < $iterations; ++$i) { if (!isset($array_flip[$var])) {} } $end = microtime(true); print "array_flip() outside loop measured + isset(): \n".($end - $start)."\n"; $array_flip = array_flip($array); $start = microtime(true); for($i = 0; $i < $iterations; ++$i) { if (!isset($array_flip[$var])) {} } $end = microtime(true); print "array_flip() outside loop not measured + isset(): \n".($end - $start)."\n"; $start = microtime(true); for($i = 0; $i < $iterations; ++$i) { foreach ($array as $entry) { if ($entry == $var) {} } } $end = microtime(true); print "foreach and compoarison: \n".($end - $start)."\n";

Abusive script

This script was stopped while abusing our resources


preferences:
55.41 ms | 406 KiB | 5 Q