diff --git a/package.json b/package.json index cd43e6c..2727b3b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "name": "pegjs-dev", "private": true, "workspaces": [ - "packages/*" + "packages/*", + "tools/*" ], "scripts": { "lint": "gulp lint", @@ -11,8 +12,8 @@ "build:parser": "gulp build:parser", "build:dist": "rollup -c", "clean": "gulp clean", + "impact": "impact master", "start": "node server.js", - "test:impact": "node test/impact master", "test": "nyc gulp", "coverage": "nyc report --reporter=text-lcov | coveralls" }, @@ -42,7 +43,6 @@ "dedent": "0.7.0", "del": "3.0.0", "eslint-config-futagozaryuu": "5", - "glob": "7.1.3", "gulp-eslint": "5.0.0", "mocha": "5.2.0", "nyc": "13.1.0", diff --git a/tools/impact/README.md b/tools/impact/README.md new file mode 100644 index 0000000..14ffc69 --- /dev/null +++ b/tools/impact/README.md @@ -0,0 +1,8 @@ +This directory contains a tool used on the PEG.js repository that measures the impact of two git commits on a number of generated parsers, extracting the benchmark speeds and generated parser sizes, comparing the results of each commit against the other before finally displaying the overall results in the console. + +From the root of the repository: + +```sh +yarn impact +yarn impact +``` diff --git a/test/impact b/tools/impact/index.js similarity index 86% rename from test/impact rename to tools/impact/index.js index 1d85614..5388286 100644 --- a/test/impact +++ b/tools/impact/index.js @@ -5,7 +5,7 @@ // speed and size. Makes sense to use only on PEG.js git repository checkout. // -/* eslint prefer-const: 0 */ +/* eslint-disable no-mixed-operators, prefer-const */ "use strict"; @@ -18,7 +18,7 @@ const glob = require( "glob" ); // Current Working Directory -const cwd = path.join( __dirname, ".." ); +const cwd = path.join( __dirname, "..", ".." ); if ( process.cwd() !== cwd ) process.chdir( cwd ); // Execution Files @@ -35,8 +35,8 @@ function binfile( ...files ) { } -let PEGJS_BIN = binfile( "packages/pegjs/bin/peg.js", "bin/peg.js", "bin/pegjs" ); -let BENCHMARK_BIN = binfile( "test/benchmark/run", "benchmark/run" ); +const PEGJS_BIN = binfile( "packages/pegjs/bin/peg.js", "bin/peg.js", "bin/pegjs" ); +const BENCHMARK_BIN = binfile( "test/benchmark/run", "benchmark/run" ); // Utils @@ -46,6 +46,12 @@ function echo( message ) { } +function print_empty_line() { + + console.log( " " ); + +} + function exec( command ) { return child_process.execSync( command, { encoding: "utf8" } ); @@ -121,6 +127,7 @@ if ( argv.length === 1 ) { } else { + print_empty_line(); console.log( dedent` Usage: @@ -132,6 +139,7 @@ if ( argv.length === 1 ) { speed and size. Makes sense to use only on PEG.js Git repository checkout. ` ); + print_empty_line(); process.exit( 1 ); } @@ -141,21 +149,24 @@ if ( argv.length === 1 ) { const branch = exec( "git rev-parse --abbrev-ref HEAD" ); let speed1, size1, speed2, size2; +print_empty_line(); + echo( `Measuring commit ${ commit_before }...` ); prepare( commit_before ); speed1 = measureSpeed(); size1 = measureSize(); -echo( " OK" + os.EOL ); +echo( " done." + os.EOL ); echo( `Measuring commit ${ commit_after }...` ); prepare( commit_after ); speed2 = measureSpeed(); size2 = measureSize(); -echo( " OK" + os.EOL ); +echo( " done." + os.EOL ); // Finish prepare( branch ); +print_empty_line(); console.log( dedent` @@ -173,7 +184,8 @@ console.log( dedent` After: ${ size2 } b Difference: ${ difference( size1, size2 ) }% - - Measured by /test/impact with Node.js ${ process.version } + - Measured by /tools/impact with Node.js ${ process.version } - Your system: ${ os.type() } ${ os.release() } ${ os.arch() }. ` ); +print_empty_line(); diff --git a/tools/impact/package.json b/tools/impact/package.json new file mode 100644 index 0000000..8bad388 --- /dev/null +++ b/tools/impact/package.json @@ -0,0 +1,10 @@ +{ + "name": "impact", + "version": "2.1.0", + "private": true, + "bin": "index.js", + "dependencies": { + "dedent": "0.7.0", + "glob": "7.1.3" + } +}