Skip to content

Commit

Permalink
Add benchmarks for runtime with many files
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed Aug 25, 2020
1 parent 09f716c commit 23229db
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions benchmarks/runtime.bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
'use strict';

const { expect } = require('chai');
const { Linter } = require('eslint');
const times = require('ramda/src/times');
const { runBenchmark, cpuSpeed } = require('./measure');
const mochaPlugin = require('../');

const recommendedRules = mochaPlugin.configs.recommended.rules;

function lintManyFilesWithAllRecommendedRules({ numberOfFiles }) {
const linter = new Linter();

linter.defineRules(mochaPlugin.rules);

const config = {
rules: Object.fromEntries(Object.entries(recommendedRules).map(([ ruleName, ruleSettings ]) => {
const [ , ruleNameWithoutPrefix ] = ruleName.split('/');

return [ ruleNameWithoutPrefix, ruleSettings ];
})),
parserOptions: {
ecmaVersion: 2018
}
};

times((index) => {
const codeToLint = `
'use strict';
const assert = require('assert');
const sinon = require('sinon');
const sut = require('./sut');
describe('SUT ${index}', function () {
let fooStub;
before(() => {
fooStub = sinon.stub(sut, 'foo');
});
after(() => {
fooStub.restore();
});
beforeEach(function (done) {
done();
});
afterEach(() => {
fooStub.reset();
});
it('should work', async function () {
const bar = {};
await sut(bar);
assert(fooStub.callCount === 42);
});
describe('nested suite', async () => {
beforeEach(async function () {
await sleep(200);
});
xit('doesn’t work yet', function () {
sut();
});
});
context('more context', function () {
it.only('only here it works', () => {
sut();
assert(true);
});
});
});
`;

linter.verify(codeToLint, config);
}, numberOfFiles);
}

describe('runtime', () => {
it('should not take longer as the defined budget to lint many files with the recommended config', () => {
const budget = 52000000 / cpuSpeed;

const { medianDuration } = runBenchmark(() => {
lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 });
}, 5);

expect(medianDuration).to.be.below(budget);
});

it('should not consume more memory as the defined budget to lint many files with the recommended config', () => {
const budget = 2400000;

const { medianMemory } = runBenchmark(() => {
lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 });
}, 5);

expect(medianMemory).to.be.below(budget);
});
});

0 comments on commit 23229db

Please sign in to comment.