Skip to content
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

refactor(benchmark): use eslint over tslint #26

Merged
merged 2 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ aliases:
# https://github.com/cypress-io/cypress-docker-images/tree/master/included
- &use_docker_cypress_included
docker:
# 3.8.0 fails with `Error: write EPIPE` when running `benchmark`!?
- image: cypress/included:3.8.2

- &workspace ~/talus
Expand Down
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-parameter-properties": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/no-unused-vars": [
"error",
{ "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }
],
"@typescript-eslint/no-use-before-define": "off",
"@nrwl/nx/enforce-module-boundaries": [
"error",
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ This project was generated using [Nx](https://nx.dev) with the following command

8. `ng generate @nrwl/angular:component sidenav-shell --project=ui --module=sidenav-shell --export`

9. `ng generate @nrwl/workspace:library model --linter=eslint`
9. `nx g @nrwl/node:application benchmark --linter=eslint`

10. `ng generate @nrwl/workspace:library model --linter=eslint`

## Installations

Expand Down
4 changes: 3 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"builder": "@nrwl/linter:lint",
"options": {
"linter": "eslint",
"config": "apps/benchmark/.eslintrc",
"tsConfig": ["apps/benchmark/tsconfig.app.json"],
"exclude": ["**/node_modules/**", "!apps/benchmark/**"]
}
Expand Down
1 change: 1 addition & 0 deletions apps/benchmark/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "../../.eslintrc", "rules": {} }
4 changes: 2 additions & 2 deletions apps/benchmark/benchmark.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
export default {
suiteName: 'Benchmark.js tests',
outputDirectory: './test-results/benchmark',
outputName: 'all.junit.xml',
outputName: 'apps-benchmark.junit.xml',
};
Empty file added apps/benchmark/src/app/.gitkeep
Empty file.
24 changes: 12 additions & 12 deletions apps/benchmark/src/app/vdb/coord.benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ suite('[Coord] write', () => {
suite('[Coord] read', () => {
const coord: Coord = [0, 0, 0];
benchmark('coord[0]', () => {
const x = coord[0];
const y = coord[1];
const z = coord[2];
const _x = coord[0];
const _y = coord[1];
const _z = coord[2];
});

benchmark('coord[X]', () => {
const x = coord[X];
const y = coord[Y];
const z = coord[Z];
const _x = coord[X];
const _y = coord[Y];
const _z = coord[Z];
});

const coordObj = { x: 0, y: 0, z: 0 };
benchmark('coordObj.x', () => {
const x = coordObj.x;
const y = coordObj.y;
const z = coordObj.z;
const _x = coordObj.x;
const _y = coordObj.y;
const _z = coordObj.z;
});
});

suite('[Coord] function parameter', () => {
const coord: Coord = [0, 1, 2];

function oneParameter(xyz: Coord): void {
const x = xyz[0];
const y = xyz[1];
const z = xyz[2];
const _x = xyz[0];
const _y = xyz[1];
const _z = xyz[2];
}

function deconstruct([x, y, z]: Coord): void {
Expand Down
18 changes: 11 additions & 7 deletions apps/benchmark/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Benchmark from 'benchmark';
import * as fs from 'fs';
import { getJunitXml, TestSuite, TestSuiteReport } from 'junit-xml';

const config = require('../benchmark.config');
import config from '../benchmark.config';

const suites: Benchmark.Suite[] = [];
const report: TestSuiteReport = {
Expand Down Expand Up @@ -36,7 +36,7 @@ export function benchmark(name: string, fn: () => void): void {
suites[suites.length - 1].add(name, fn);
}

function logSummary(suiteToLog: any): void {
function logSummary(suiteToLog: Benchmark.Suite): void {
logFastestBenchmarkNames(suiteToLog);

const benchmarks = Array.from({ length: suiteToLog.length }, (x, i) => suiteToLog[i]);
Expand All @@ -48,11 +48,11 @@ function logSummary(suiteToLog: any): void {
});
}

function logFastestBenchmarkNames(suiteToLog: any): void {
function logFastestBenchmarkNames(suiteToLog: Benchmark.Suite): void {
const fastestBenchmarkNames = suiteToLog.filter('fastest').map(bm => bm.name);
const conjugatedVerbBe = fastestBenchmarkNames.length > 1 ? 'are' : 'is';

console.log(`\n${suiteToLog.name}`);
console.log(`\n${suiteToLog['name']}`);
console.log(` Fastest ${conjugatedVerbBe} "${fastestBenchmarkNames.join(', ')}"`);
}

Expand All @@ -63,7 +63,7 @@ function logBenchmarkBar(highestHz: number, bm: Benchmark): void {
const filledBarLength = barPercentage / charsPerOnePercentage;
const emptyBarLength = (100 - barPercentage) / charsPerOnePercentage;

const createBar = (length, char) => Array.from({ length }, () => char).join('');
const createBar = (length, char): string => Array.from({ length }, () => char).join('');
const filledBar = `${createBar(Math.floor(filledBarLength), '-')}`;
const emptyBar = createBar(Math.ceil(emptyBarLength), ' ');

Expand Down Expand Up @@ -97,17 +97,21 @@ function everySuiteFinished(): boolean {

function writeReportToFile(): void {
const folderPath = `${process.cwd()}/${config.outputDirectory}`;
const filePath = `${config.outputDirectory}/${config.outputName}`;

fs.promises
.mkdir(folderPath, { recursive: true })
.then(() => fs.promises.writeFile(`${folderPath}/${config.outputName}`, getJunitXml(report)))
.then(() => console.log('\nJUnit report saved!'))
.then(() => fs.promises.writeFile(filePath, getJunitXml(report)))
.then(() => console.log(`\nJUnit report saved:\n ${filePath}`))
.catch((err: NodeJS.ErrnoException) => {
console.log(err);
process.exit(err.errno);
});
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
declare const require: any;

(function runAllBenchmarks(): void {
// find all benchmark files
const context = require.context('./', true, /\.benchmark\.ts$/);
Expand Down
4 changes: 0 additions & 4 deletions apps/benchmark/tslint.json

This file was deleted.