Skip to content

test: basic setup for benchmarks #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fb84c83
test: basic setup for benchmark of restrict-plus-operands
armano2 Jan 23, 2019
1600833
test: remove ts from benchmark and migrate code to js
armano2 Jan 24, 2019
84b2c1f
test: add benchmark with multiple files
armano2 Jan 24, 2019
657b085
test: small update
armano2 Jan 24, 2019
351f7ba
test: more tests
armano2 Jan 24, 2019
b19a0bb
Merge branch 'master' into benchmark
JamesHenry Jan 24, 2019
a304aab
test(benchmark): simplify benchmarks
armano2 Jan 24, 2019
25f7fe7
test(benchmark): generate readme, and fix linting issues
armano2 Jan 24, 2019
4c5285a
test(benchmark): improve readme generation
armano2 Jan 24, 2019
31478c0
test: add fixtures to prettierignore
armano2 Jan 24, 2019
8a721e2
test: add benchmark for parsers (ts-estree vs parse)
armano2 Jan 25, 2019
53d43b8
test: update benchmarks
armano2 Jan 26, 2019
b4a1ddb
Merge branch 'master' into benchmark
armano2 Jan 26, 2019
9d04224
test: update benchmarks
armano2 Jan 26, 2019
1cd1b44
chore: fix linting
armano2 Jan 26, 2019
0449862
chore: remove dead dependencies
armano2 Jan 26, 2019
af99f6a
test: add missing file reading in parsers
armano2 Jan 27, 2019
6318927
Merge master into benchmark
armano2 Jan 27, 2019
698acf9
test: add complex test case for parsers
armano2 Jan 28, 2019
ebb7abd
Merge branch 'master' into benchmark
armano2 Jan 29, 2019
aad4898
test: do not generate results (its objective, for each environment)
armano2 Jan 29, 2019
7b1e42e
Merge branch 'master' into benchmark
armano2 Jan 29, 2019
b7a1949
Merge branch 'master' into benchmark
armano2 Jan 30, 2019
fddc4fe
test: add missing tsconfigRootDir to eslintrc
armano2 Jan 30, 2019
358d0a6
test: migrate config to json and apply tsconfigRootDir for useServices
armano2 Jan 30, 2019
70e04c8
Revert "test: migrate config to json and apply tsconfigRootDir for us…
armano2 Jan 30, 2019
c8665f6
test: add e2e benchmark
armano2 Jan 30, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pids
*.pid
*.seed
*.pid.lock
package-lock.json

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
Expand Down
5 changes: 2 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
**/tests/fixtures/**/*
**/fixtures/**/*
**/dist
**/coverage
**/shared-fixtures
**/tests/integration/fixtures/**/*
**/lib/configs/recommended.json
**/.vscode
**/.nyc_output
**/.nyc_output
95 changes: 95 additions & 0 deletions packages/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const Benchmark = require('benchmark');

function createBenchmark(name, directory, files, useServices) {
return new Promise((resolve, reject) => {
const suite = new Benchmark.Suite(name, {
async: true
});
suite
.add('tslint', function() {
const result = require('./tslint-runner').runTSLint(
directory,
files,
useServices
);
if (typeof result !== 'string') {
throw new Error('something went wrong');
}
})
.add('eslint', function() {
const result = require('./eslint-runner').runESLint(
directory,
files,
useServices
);
if (typeof result !== 'string') {
throw new Error('something went wrong');
}
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('error', function(e) {
reject(e);
})
.on('complete', function() {
console.log(
`Fastest is ${this.filter('fastest')
.map(i => i.name)
.join(', ')}`
);
resolve();
})
.run();
});
}

async function runAllBenchmarks(scenarios) {
for (const scenario of scenarios) {
console.log(scenario.name);
await createBenchmark(
scenario.name,
scenario.directory,
scenario.files,
scenario.useServices
);
}
}

runAllBenchmarks([
{
name: 'Single File: restrict-plus-operands',
directory: 'fixtures/restrict-plus-operands/',
useServices: true,
files: ['fixtures/restrict-plus-operands/test1.ts']
},
{
name: 'Multi File: restrict-plus-operands',
directory: 'fixtures/restrict-plus-operands/',
useServices: true,
files: [
'fixtures/restrict-plus-operands/test1.ts',
'fixtures/restrict-plus-operands/test2.ts',
'fixtures/restrict-plus-operands/test3.ts'
]
},
{
name: 'Single File: no-empty-interface',
directory: 'fixtures/no-empty-interface/',
useServices: false,
files: ['fixtures/no-empty-interface/test1.ts']
},
{
name: 'Multi File: no-empty-interface',
directory: 'fixtures/no-empty-interface/',
useServices: false,
files: [
'fixtures/no-empty-interface/test1.ts',
'fixtures/no-empty-interface/test2.ts',
'fixtures/no-empty-interface/test3.ts'
]
}
]).catch(e => {
console.log(e);
});
66 changes: 66 additions & 0 deletions packages/benchmark/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const Benchmark = require('benchmark');
const child_process = require('child_process');
const path = require('path');

function normalizeCommand(command) {
return path.normalize(command);
}

function createBenchmark(name, directory, files, useServices) {
return new Promise((resolve, reject) => {
const suite = new Benchmark.Suite(name, {
async: true
});
suite
.add('tslint', function() {
let hasError = false;
try {
child_process.execSync(
normalizeCommand('./node_modules/.bin/tslint') +
' -p fixtures/restrict-plus-operands/tsconfig.json "fixtures/restrict-plus-operands/*.ts"'
);
} catch (e) {
// console.error(e.output ? e.output.toString() : e);
hasError = true;
}
if (!hasError) {
throw new Error('something went wrong');
}
})
.add('eslint', function() {
let hasError = false;
try {
child_process.execSync(
normalizeCommand('./node_modules/.bin/eslint') +
' --ext .ts "fixtures/restrict-plus-operands/*.ts"'
);
} catch (e) {
// console.error(e.output ? e.output.toString() : e);
hasError = true;
}
if (!hasError) {
throw new Error('something went wrong');
}
})
// add listeners
.on('cycle', function(event) {
console.log(String(event.target));
})
.on('error', function(e) {
reject(e);
})
.on('complete', function() {
console.log(
`Fastest is ${this.filter('fastest')
.map(i => i.name)
.join(', ')}`
);
resolve();
})
.run();
});
}

createBenchmark().catch(e => {
console.log(e);
});
56 changes: 56 additions & 0 deletions packages/benchmark/eslint-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const eslint = require('eslint');
const path = require('path');
const fs = require('fs');

// exports.runESLint = function(directory, files, useServices) {
// const linter = new eslint.CLIEngine({
// files: files,
// configFile: `${directory}.eslintrc.js`,
// extensions: ['.js', '.ts']
// });
// const results = [];
// for (const file of files) {
// results.push(
// linter.executeOnText(
// fs.readFileSync(path.join(__dirname, file), 'utf8'),
// file,
// true
// )
// );
// }
//
// if (results[0].errorCount === 0) {
// throw new Error('something went wrong');
// }
// if (
// results[0].results[0].messages[0].message !==
// 'An empty interface is equivalent to `{}`.'
// ) {
// throw new Error('something went wrong');
// }
// };

exports.runESLint = function(directory, files, useServices) {
const linter = new eslint.Linter();
linter.defineRule(
'@typescript-eslint/no-empty-interface',
require('@typescript-eslint/eslint-plugin/lib/rules/no-empty-interface')
);
linter.defineRule(
'@typescript-eslint/restrict-plus-operands',
require('@typescript-eslint/eslint-plugin/lib/rules/restrict-plus-operands')
);
let result;
for (const file of files) {
result = linter.verify(
fs.readFileSync(path.join(__dirname, file), 'utf8'),
require(path.join(__dirname, `./${directory}.eslintrc.js`)),
file
);
}
if (result.length === 0) {
throw new Error('something went wrong');
}

return result[0].message;
};
Loading