Skip to content

Commit

Permalink
Add exports field to package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed Aug 23, 2024
1 parent 2b717c6 commit 622edac
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .c8rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"functions": 100,
"branches": 100,
"check-coverage": true,
"extension": [".js", ".mjs"],
"extension": [".js"],
"instrument": false,
"src": ".",
"reporter": ["lcov", "text-summary"],
"reportDir": "./target/coverage",
"tempDirectory": "./target/c8-temporary-output",
"exclude": ["target", "test", "benchmarks/", "eslint.config.mjs"]
"exclude": ["target", "test", "benchmarks/", "eslint.config.js"]
}
8 changes: 4 additions & 4 deletions benchmarks/measure.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os from 'node:os';
import { performance as performanceHooks } from 'node:perf_hooks';
import { filter, lt as isLowerThan, map, median, prop, times } from 'rambda';
import { filter, lte as isLowerThanOrEquals, map, median, prop, times } from 'rambda';

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

Expand All @@ -13,7 +13,7 @@ export async function importFresh(modulePath) {
await import(cacheBustingModulePath);
}

const isNegative = isLowerThan(0);
const isPositiveNumber = isLowerThanOrEquals(0);

export function runSyncBenchmark(fn, count) {
const results = [];
Expand All @@ -31,7 +31,7 @@ export function runSyncBenchmark(fn, count) {
}, count);

const medianDuration = median(map(prop('duration'), results));
const medianMemory = median(filter(isNegative, map(prop('memory'), results)));
const medianMemory = median(filter(isPositiveNumber, map(prop('memory'), results)));

return { medianDuration, medianMemory };
}
Expand All @@ -57,7 +57,7 @@ export async function runAsyncBenchmark(fn, count) {
}

const medianDuration = median(map(prop('duration'), results));
const medianMemory = median(filter(isNegative, map(prop('memory'), results)));
const medianMemory = median(filter(isPositiveNumber, map(prop('memory'), results)));

return { medianDuration, medianMemory };
}
20 changes: 14 additions & 6 deletions benchmarks/runtime.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,33 @@ function lintManyFilesWithAllRecommendedRules(options) {

const iterations = 50;

describe('runtime', function () {
it('should not take longer as the defined budget to lint many files with the recommended config', function () {
describe('runtime', function() {

Check failure on line 81 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 20

Require whitespace(s)

Check failure on line 81 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 20

Missing space before function parentheses

Check failure on line 81 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 21

Require whitespace(s)

Check failure on line 81 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 21

Missing space before function parentheses

Check failure on line 81 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 20

Require whitespace(s)

Check failure on line 81 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 20

Missing space before function parentheses

Check failure on line 81 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 21

Require whitespace(s)

Check failure on line 81 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 21

Missing space before function parentheses
it('should not take longer as the defined budget to lint many files with the recommended config', function() {

Check failure on line 82 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 20

Require whitespace(s)

Check failure on line 82 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 20

Missing space before function parentheses

Check failure on line 82 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 21

Require whitespace(s)

Check failure on line 82 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 21

Missing space before function parentheses

Check failure on line 82 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 20

Require whitespace(s)

Check failure on line 82 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 20

Missing space before function parentheses

Check failure on line 82 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 21

Require whitespace(s)

Check failure on line 82 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 21

Missing space before function parentheses
const cpuAgnosticBudget = 3_250_000;
const budget = cpuAgnosticBudget / cpuSpeed;

const { medianDuration } = runSyncBenchmark(() => {
lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 });
}, iterations);

assert.strictEqual(medianDuration < budget, true);
assert.strictEqual(
medianDuration < budget,
true,
`Expected duration ${medianDuration} to be lower than budget ${budget}`
);
});

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

Check failure on line 97 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 20

Require whitespace(s)

Check failure on line 97 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 20

Missing space before function parentheses

Check failure on line 97 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 21

Require whitespace(s)

Check failure on line 97 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 21

Missing space before function parentheses

Check failure on line 97 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 20

Require whitespace(s)

Check failure on line 97 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 20

Missing space before function parentheses

Check failure on line 97 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 21

Require whitespace(s)

Check failure on line 97 in benchmarks/runtime.bench.js

View workflow job for this annotation

GitHub Actions / Node 21

Missing space before function parentheses
const budget = 2_250_000;

const { medianMemory } = runSyncBenchmark(() => {
lintManyFilesWithAllRecommendedRules({ numberOfFiles: 350 });
}, iterations);

assert.strictEqual(medianMemory < budget, true);
assert.strictEqual(
medianMemory < budget,
true,
`Expected memory ${medianMemory} to be lower than budget ${budget}`
);
});
});
14 changes: 11 additions & 3 deletions benchmarks/startup.bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ describe('startup / require time', function () {
await importFresh('../index.js');
}, iterations);

assert.strictEqual(medianDuration < budget, true);
assert.strictEqual(
medianDuration < budget,
true,
`Expected duration ${medianDuration} to be lower than budget ${budget}`
);
});

it('should not consume more memory as the defined budget', async function () {
const budget = 50_000;
const budget = 225_000;

const { medianMemory } = await runAsyncBenchmark(async () => {
await importFresh('../index.js');
}, iterations);

assert.strictEqual(medianMemory < budget, true);
assert.strictEqual(
medianMemory < budget,
true,
`Expected memory ${medianMemory} to be lower than budget ${budget}`
);
});
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"node": ">=20.0.0"
},
"main": "index.js",
"exports": "./index.js",
"files": [
"index.js",
"lib/",
Expand Down

0 comments on commit 622edac

Please sign in to comment.