Skip to content

Instantly share code, notes, and snippets.

@lorenzo
Created July 8, 2014 14:55
Show Gist options
  • Save lorenzo/1dfae96ee74bc3cf029f to your computer and use it in GitHub Desktop.
Save lorenzo/1dfae96ee74bc3cf029f to your computer and use it in GitHub Desktop.
<?php
define('LOOP',1000000);
class ClassA {
}
function a($arg1, ClassA $arg2=null, ClassA $arg3=null, ClassA $arg4=null) {};
function b($arg1, $arg2=null, $arg3=null, $arg4=null) {};
function f1() {
$a = new ClassA();
for($i=0; $i<LOOP; ++$i) {
a(1, $a, $a, $a);
}
}
function f2() {
$a = new ClassA();
for($i=0; $i<LOOP; ++$i) {
b(1, $a, $a, $a);
}
}
$start = microtime(true);
f1();
$stop = microtime(true);
$time1 = $stop - $start;
$start = microtime(true);
f2();
$stop = microtime(true);
$time2 = $stop - $start;
echo $time1 . "\t";
echo $time2 . "\n";
echo ((($time1 - $time2) / $time1) * 100) . '% difference' . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment