Skip to content

Instantly share code, notes, and snippets.

@stephenharris
Created April 19, 2016 10:23
Show Gist options
  • Save stephenharris/44b5b5d2bbb3f50e93fd0a5882d3fccd to your computer and use it in GitHub Desktop.
Save stephenharris/44b5b5d2bbb3f50e93fd0a5882d3fccd to your computer and use it in GitHub Desktop.
Simple wp-cli based benchmark command
<?php
if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
return;
}
/**
* Implements example command.
*/
class Benchmark_Command extends WP_CLI_Command {
/**
* Runs mail benchmark
*
* ## OPTIONS
*
* [--iterations=<integer>]
* : How many iterations to run
*
* ## EXAMPLES
*
* wp benchmark mail --run=10000
*
* @when before_wp_load
*/
function mail( $args, $assoc_args ) {
$assoc_args = array_merge( array( 'iterations' => 1000 ), $assoc_args );
$iterations = (int) $assoc_args['iterations'];
$start = microtime( true );
for ( $i = 0; $i < $iterations; $i ++ ) {
wp_mail( '[email protected]', 'A follow up short email', 'Short email' );
}
$end = microtime( true );
$duration = $end - $start;
WP_CLI::success( "$iterations runs took $duration ms" );
exit;
}
}
WP_CLI::add_command( 'benchmark', 'Benchmark_Command' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment