- microtime: documentation ( source)
- round: documentation ( source)
- test1: documentation ( source)
- test2: documentation ( source)
<?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;
}
$start1 = microtime(1);
for ($i = 1; $i < 10000; $i++) {
test1();
}
$start1 -= microtime(1);
echo "test1: $start1";
$start2 = microtime(1);
for ($i = 1; $i < 10000; $i++) {
test2();
}
$start2 -= microtime(1);
echo "\ntest2: $start2\n\n";
if ($start1 < $start2) {
$perc = round(($start1 / $start2) * 100,2)-100;
echo "Test1 is $perc"."% faster than Test2";
}
if ($start2 < $start1) {
$perc = round(($start2 / $start1) * 100,2)-100;
echo "Test2 is $perc"."% faster than Test1";
}