Skip to content

Instantly share code, notes, and snippets.

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 mikeschinkel/9a411297c047020c13e215885da9d12a to your computer and use it in GitHub Desktop.
Save mikeschinkel/9a411297c047020c13e215885da9d12a to your computer and use it in GitHub Desktop.
Benchmark for single WordPress action hook
<?php
define( 'ITERATIONS', 1000000 );
require( __DIR__ . '/wp-load.php' );
add_action('my_action', '__return_null' );
header('Content-type: text/plain');
time_it( 'hook an action with no parameters: ', function($condition) { do_action('my_action'); });
function time_it( $what, $callable ) {
$time_start = microtime( true );
$condition = true;
for ( $i = 0; $i < ITERATIONS; $i ++ ) {
call_user_func( $callable, $condition );
$condition = !$condition;
}
printf( "\n%s %s %.3f",
number_format(ITERATIONS),
$what,
$delta = microtime( true ) - $time_start
);
return $delta;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment