Skip to content

Instantly share code, notes, and snippets.

@kotas
Created February 8, 2011 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kotas/816845 to your computer and use it in GitHub Desktop.
Save kotas/816845 to your computer and use it in GitHub Desktop.
require_once vs autoload
<?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);
}
<?php
class B {
public static function noop() { }
}
<?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