Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.