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

Improve benchmark test reliability #277

Merged
merged 1 commit into from
Mar 5, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 16 additions & 1 deletion benchmarks/measure.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@ const times = require('ramda/src/times');
const median = require('ramda/src/median');
const map = require('ramda/src/map');
const prop = require('ramda/src/prop');
const semver = require('semver');

const [ { speed: cpuSpeed } ] = os.cpus();

function getNodeVersionMultiplier() {
const currentNodeVersion = process.version;

if (semver.lt(currentNodeVersion, '14.0.0') && semver.gte(currentNodeVersion, '12.0.0')) {
return 1.5;
}

if (semver.lt(currentNodeVersion, '12.0.0')) {
return 2;
}

return 1;
}

function clearRequireCache() {
Object.keys(require.cache).forEach(function (key) {
delete require.cache[key];
Expand Down Expand Up @@ -36,4 +51,4 @@ function runBenchmark(fn, count) {
return { medianDuration, medianMemory };
}

module.exports = { runBenchmark, clearRequireCache, cpuSpeed };
module.exports = { runBenchmark, clearRequireCache, cpuSpeed, getNodeVersionMultiplier };
5 changes: 3 additions & 2 deletions benchmarks/runtime.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { Linter } = require('eslint');
const times = require('ramda/src/times');
const toPairs = require('ramda/src/toPairs');
const fromPairs = require('ramda/src/fromPairs');
const { runBenchmark, cpuSpeed } = require('./measure');
const { runBenchmark, cpuSpeed, getNodeVersionMultiplier } = require('./measure');
const mochaPlugin = require('../');

const recommendedRules = mochaPlugin.configs.recommended.rules;
Expand Down Expand Up @@ -85,7 +85,8 @@ function lintManyFilesWithAllRecommendedRules({ numberOfFiles }) {

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

const { medianDuration } = runBenchmark(() => {
lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 });
Expand Down
26 changes: 22 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"eslint-plugin-unicorn": "^21.0.0",
"mocha": "^8.1.0",
"nyc": "^15.1.0",
"pr-log": "^4.0.0"
"pr-log": "^4.0.0",
"semver": "^7.3.4"
},
"peerDependencies": {
"eslint": ">=7.0.0"
Expand Down