Skip to content

Commit

Permalink
Merge pull request #571 from gkjohnson/bench-compare
Browse files Browse the repository at this point in the history
Add bench compare script
  • Loading branch information
gkjohnson authored Aug 24, 2023
2 parents 865a310 + df88e28 commit 7bace4c
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 6 deletions.
64 changes: 64 additions & 0 deletions benchmark/compare-bench-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import fs from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';

const CRITICAL_ONLY = process.argv.includes( '--critical' );
const __filename = fileURLToPath( import.meta.url );
const __dirname = dirname( __filename );

const prData = JSON.parse( fs.readFileSync( join( __dirname, '../pr-benchmark.json' ) ) );
const maData = JSON.parse( fs.readFileSync( join( __dirname, '../master-benchmark.json' ) ) );

const exclude = [ 'iterations', 'name' ];
for ( let i = 0; i < prData.length; i ++ ) {

const prInfo = prData[ i ];
const maInfo = maData[ i ];

const prResults = prInfo.results;
const maResults = maInfo.results;

let finalTable = '';
for ( let j = 0; j < prResults.length; j ++ ) {

const prData = prResults[ j ];
const maData = maResults[ j ];

let result = '';
for ( const key in prData ) {

if ( exclude.includes( key ) ) continue;

const prValue = prData[ key ];
const maValue = maData[ key ];
const delta = prValue - maValue;
const perc = delta === 0 ? 0 : delta / maValue;

if ( CRITICAL_ONLY && perc > 3 || ! CRITICAL_ONLY ) {

const star = perc > 1 ? '*&nbsp;' : '&nbsp;&nbsp;';
result += `| ${ star } ${ key } | ${ maValue.toFixed( 5 ) } ms | ${ prValue.toFixed( 5 ) } ms | ${ delta.toFixed( 5 ) } ms | ${ ( perc * 100 ).toFixed( 5 ) } % |\n`;

}

}

if ( result ) {

finalTable += `| ${ prData.name } | | | | |\n`;
finalTable += result;

}

}

if ( finalTable ) {

console.log( `\n**${ prInfo.name }**` );
console.log( '| | before | after | delta | increase |' );
console.log( '|---|---|---|---|---|' );
console.log( finalTable );

}

}
55 changes: 55 additions & 0 deletions benchmark/run-bench-compare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import simpleGit from 'simple-git';
import { exec } from 'child_process';

( async() => {

const git = simpleGit();
const status = await git.status();

const modified = status.modified.length + status.created.length + status.renamed.length + status.deleted.length;
if ( modified !== 0 ) {

console.error( 'Current branch is not clean' );
process.exit( 1 );

}

const currentBranch = status.current;

console.log( 'Running Benchmark' );
await runScript( 'node ./benchmark/run-benchmark.js --long --json > pr-benchmark.json' );

console.log( 'Running Master Benchmark' );
await git.checkout( 'master' );
await runScript( 'node ./benchmark/run-benchmark.js --long --json > master-benchmark.json' );

console.log( 'Comparing Benchmarks' );
console.log();

await runScript( 'node ./benchmark/compare-bench-json.js --critical' );
console.log( '<details><summary>Full Benchmark</summary>' );

await runScript( 'node ./benchmark/compare-bench-json.js' );
console.log( '</details>' );

await git.checkout( currentBranch );

} )();

function runScript( command ) {

return new Promise( ( resolve, reject ) => {

const proc = exec( command );
proc.stderr.pipe( process.stderr );
proc.stdout.pipe( process.stdout );
proc.on( 'exit', code => {

if ( code === 0 ) resolve();
else reject();

} );

} );

}
69 changes: 63 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"parcel": "^2.0.0",
"rollup": "^2.58.0",
"script-loader": "^0.7.2",
"simple-git": "^3.19.1",
"simplex-noise": "^2.4.0",
"static-server": "^2.2.1",
"stats.js": "^0.17.0",
Expand Down

0 comments on commit 7bace4c

Please sign in to comment.