Skip to content

Instantly share code, notes, and snippets.

@Ocramius
Created November 13, 2012 09:18
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 Ocramius/72f95cc0801b4e2cb568 to your computer and use it in GitHub Desktop.
Save Ocramius/72f95cc0801b4e2cb568 to your computer and use it in GitHub Desktop.
Closure vs call_user_func performance
<?php
$iterations = 100000;
$start = microtime(true);
$closure = null;
for ($i = 0; $i < $iterations; $i += 1) {
if ($closure) {
$closure();
}
}
var_dump(microtime(true) - $start);
$start = microtime(true);
$closure = function () {};
for ($i = 0; $i < $iterations; $i += 1) {
$closure();
}
var_dump(microtime(true) - $start);
$start = microtime(true);
$closure = function () {};
for ($i = 0; $i < $iterations; $i += 1) {
call_user_func($closure);
}
var_dump(microtime(true) - $start);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment