Skip to content

Instantly share code, notes, and snippets.

@pifantastic
Created August 18, 2011 20:19
Show Gist options
  • Save pifantastic/1155079 to your computer and use it in GitHub Desktop.
Save pifantastic/1155079 to your computer and use it in GitHub Desktop.
Looks like calling an empty function is faster than checking if a function exists. Could be handy designing frameworks.
3.93 ms
1.68 ms
<?php
profiler::start('function_exists');
for ($x = 0; $x < 10000; $x++) {
function_exists('i_dont');
}
echo text::seconds(profiler::stop('function_exists')->time->delta)."\n";
function foo() {}
profiler::start('empty');
for ($x = 0; $x < 10000; $x++) {
foo();
}
echo text::seconds(profiler::stop('empty')->time->delta)."\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment