Skip to content

Commit

Permalink
Improve benchmark test reliability
Browse files Browse the repository at this point in the history
Since older node versions are not as fast as the latest node version we
should take that into account and increase the performance budget for
older node versions.
  • Loading branch information
lo1tuma committed Mar 5, 2021
1 parent faa8bbf commit 475c217
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
17 changes: 16 additions & 1 deletion benchmarks/measure.js
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
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
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

0 comments on commit 475c217

Please sign in to comment.