Skip to content

Instantly share code, notes, and snippets.

@dmsnell
Last active October 29, 2017 14:37
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 dmsnell/0849dec331d000e25e649fa351ba2db6 to your computer and use it in GitHub Desktop.
Save dmsnell/0849dec331d000e25e649fa351ba2db6 to your computer and use it in GitHub Desktop.
Run the parser from Gutenberg over test documents to measure its speed
<?php
/**
* Set the $RUNS and run `php -f benchmark-gutenberg-php-parser.php`
*/
// I ran this file from the `Gutenberg/lib` directory
require_once( 'parser.php' );
$RUNS = 2000;
$content = file_get_contents( 'https://pastebin.com/raw/R8Zue5kQ' );
$parser = new Gutenberg_PEG_Parser;
$tic = microtime( true );
for ( $i = 0; $i < $RUNS; $i++ ) {
$parser->parse( $content );
}
$toc = microtime( true );
$delta = $toc - $tic;
echo "Took {$delta}s" . PHP_EOL;
$avg = $delta * 1000 / $RUNS;
echo "Took average {$avg}ms" . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment