Created
October 3, 2010 19:26
-
-
Save Zae/608839 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function vs constant test | |
* | |
* Constant should be faster with the interpreter, but maybe the compiler inlines the function? | |
* | |
*/ | |
class Test{ | |
var $runs = 10000000; | |
const constant = 'IAMCONST'; | |
function func(){ return 'IAMFUNC';} | |
public function testfunction(){ | |
$start = microtime(true); | |
for($i=0; $i<$this->runs; $i++){ | |
$a = $this->func(); | |
} | |
return microtime(true) - $start; | |
} | |
public function testconst(){ | |
$start = microtime(true); | |
for($i=0;$i<$this->runs; $i++){ | |
$a = self::constant; | |
} | |
return microtime(true) - $start; | |
} | |
} | |
$test = new Test(); | |
print_r(array("Constant" => $test->testconst())); | |
print_r(array("Function" => $test->testfunction())); | |
exit("EXIT"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment