Browse Source

Move test/impact to tools/impact

master
Futago-za Ryuu 3 years ago
parent
commit
9c039ce79b
  1. 6
      package.json
  2. 8
      tools/impact/README.md
  3. 26
      tools/impact/index.js
  4. 10
      tools/impact/package.json

6
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",

8
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 <commit>
yarn impact <commit_before> <commit_after>
```

26
test/impact → 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();

10
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"
}
}
Loading…
Cancel
Save