- Output for 5.6.38, 7.1.21 - 7.1.22, 7.2.10
Process exited with code 137.
<?php
function test1() {
$str = 'derp';
if ($str != 'files' && $str != 'something' && $str != 'Derrr') {
return;
}
return;
}
function test2() {
$str = 'derp';
switch ($str) {
case 'files':
case 'something':
case 'Derrr':
break;
default:
return;
}
return;
}
function runTest1() {
$start1 = microtime(1);
for ($i = 1; $i < 10000; $i++) {
test1();
}
$start1 -= microtime(1);
return $start1;
}
function runTest2() {
$start2 = microtime(1);
for ($i = 1; $i < 10000; $i++) {
test2();
}
$start2 -= microtime(1);
return $start2;
}
$tests2 = 0;
for($i = 0;$i<1000;$i++) {
$tests2 += runTest2();
}
$start2 = $tests2 / 1000;
$tests1 = 0;
for($i = 0;$i<1000;$i++) {
$tests1 += runTest1();
}
$start1 = $tests1 / 1000;
if ($start1 < $start2) {
$perc = 100-round(($start2 / $start1) * 100,2);
echo "Test1 is $perc"."% faster than Test2";
}
if ($start2 < $start1) {
$perc = 100-round(($start1 / $start2) * 100,2);
echo "Test2 is $perc"."% faster than Test1";
}