1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
<?php
/**
* Fuzz test.
*/
require 'random.php';
if ( !function_exists( 'wikidiff2_inline_diff' ) ) {
die( "wikidiff2 not found, nothing to test\n" );
}
if ( !function_exists( 'wikidiff2_inline_json_diff' ) ) {
die( "wikidiff2 not found, nothing to test\n" );
}
// Bail out early in case of any problems
error_reporting( E_ALL | E_STRICT );
/*set_error_handler( function( $errno , $errstr ) {
echo htmlspecialchars( $errstr );
die ( 1 );
} );//*/
echo "Performing an infinite fuzz test, press Ctrl+C to end...\n";
$count = 0;
$totalTime = 0;
$chunkTime = 0;
while ( true ) {
list( $left, $right ) = Random::randomData();
$contextLines = mt_rand( 0, 10 );
$time = microtime( true );
wikidiff2_do_diff( $left, $right, $contextLines );
wikidiff2_inline_diff( $left, $right, $contextLines );
wikidiff2_inline_json_diff( $left, $right, $contextLines );
$time = microtime( true ) - $time;
$totalTime += $time;
$chunkTime += $time;
if ( ++$count % 100 == 0 ) {
$perIteration = round( $totalTime / $count, 3 );
$perIterationInChunk = round( $chunkTime / 100, 3 );
$chunkTime = 0;
echo " $count iterations, avg. iteration time $perIteration ($perIterationInChunk last 100 iterations)\n";
}
}
|