Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into speedup-rules
  • Loading branch information
szuend committed Mar 5, 2021
2 parents f5ed733 + 2bdeed5 commit 327eaf3
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
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

0 comments on commit 327eaf3

Please sign in to comment.