-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #571 from gkjohnson/bench-compare
Add bench compare script
- Loading branch information
Showing
4 changed files
with
183 additions
and
6 deletions.
There are no files selected for viewing
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
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 ? '* ' : ' '; | ||
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 ); | ||
|
||
} | ||
|
||
} |
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
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(); | ||
|
||
} ); | ||
|
||
} ); | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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