Created
April 25, 2019 04:33
-
-
Save mikeschinkel/9a411297c047020c13e215885da9d12a to your computer and use it in GitHub Desktop.
Benchmark for single WordPress action hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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