Created
February 8, 2011 17:52
-
-
Save kotas/816845 to your computer and use it in GitHub Desktop.
require_once vs autoload
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 benchmark_using_require_once() { | |
require_once 'b.php'; | |
B::noop(); | |
} | |
function benchmark_using_autoload() { | |
C::noop(); | |
} | |
spl_autoload_register(function () { include 'c.php'; }); | |
foreach (array( | |
'benchmark_using_require_once', | |
'benchmark_using_autoload', | |
) as $f) { | |
$s = microtime(true); | |
for ($i = 0; $i < 10000; $i++) { | |
call_user_func($f); | |
} | |
$e = microtime(true); | |
printf("%s: %.4f sec\n", $f, $e - $s); | |
} |
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 | |
class B { | |
public static function noop() { } | |
} |
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 | |
class C { | |
public static function noop() { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment