-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
143 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/results.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { generateTests } = require('../utils'); | ||
|
||
describe('Passing suite', () => { | ||
test.each(generateTests())('%i + %i should be %i', (a, b, c) => { | ||
expect(a + b).toBe(c); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { generateTests } = require('../utils'); | ||
|
||
describe('Failing suite', () => { | ||
test.each(generateTests())('%i + %i should be %i', (a, b, c) => { | ||
expect(a + b).not.toBe(c); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { generateTests } = require('../utils'); | ||
|
||
describe('Skipped suite', () => { | ||
test.skip.each(generateTests())('%i + %i should be %i', (a, b, c) => { | ||
expect(a + b).toBe(c); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const fs = require('fs'); | ||
|
||
/** | ||
* @implements {import('@jest/reporters').Reporter} | ||
*/ | ||
class BenchmarkReporter { | ||
onRunComplete(testContexts, results) { | ||
const duration = Date.now() - results.startTime; | ||
const preset = process.env.PRESET; | ||
const numTests = results.numTotalTests; | ||
|
||
if (preset) { | ||
let results; | ||
try { | ||
results = JSON.parse(fs.readFileSync('results.json', 'utf8')); | ||
} catch { | ||
results = {}; | ||
} | ||
|
||
results[numTests] = results[numTests] || {}; | ||
results[numTests][preset] = duration; | ||
|
||
fs.writeFileSync('results.json', JSON.stringify(results, null, 2)); | ||
} | ||
} | ||
} | ||
|
||
module.exports = BenchmarkReporter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const PRESET = process.env.PRESET || 'metadata-N'; | ||
|
||
const mixins = { | ||
env: () => ({ | ||
testEnvironment: 'jest-metadata/environment-node', | ||
}), | ||
reporter: (enable) => ({ | ||
reporters: [ | ||
...(enable ? ['jest-metadata/reporter'] : []), | ||
'./benchmarkReporter', | ||
], | ||
}), | ||
workers: (n) => ({ | ||
maxWorkers: n, | ||
}), | ||
}; | ||
|
||
const presets = { | ||
'metadata-1': { | ||
...mixins.env(), | ||
...mixins.reporter(true), | ||
...mixins.workers(3), | ||
}, | ||
'metadata-N': { | ||
...mixins.env(), | ||
...mixins.reporter(true), | ||
...mixins.workers(3), | ||
}, | ||
'fallback-1': { | ||
...mixins.reporter(true), | ||
...mixins.workers(1), | ||
}, | ||
'fallback-N': { | ||
...mixins.reporter(true), | ||
...mixins.workers(3), | ||
}, | ||
'baseline-1': { | ||
...mixins.reporter(false), | ||
...mixins.workers(1), | ||
}, | ||
'baseline-N': { | ||
...mixins.reporter(false), | ||
...mixins.workers(3), | ||
}, | ||
}; | ||
|
||
module.exports = { | ||
...presets[PRESET], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "@jest-metadata/benchmark", | ||
"description": "Benchmarks to avoid performance regressions in jest-metadata", | ||
"private": true, | ||
"version": "1.0.0-beta.13", | ||
"devDependencies": { | ||
"cross-env": "^7.0.3", | ||
"jest": "latest", | ||
"jest-metadata": "^1.0.0-beta.13" | ||
}, | ||
"scripts": { | ||
"bench:dev": "npm run build --workspace=jest-metadata && npm run bench", | ||
"bench": "npm run bench:1 && npm run bench:10 && npm run bench:100 && npm run bench:1000 && npm run bench:10000", | ||
"bench:1": "cross-env NUM_TESTS=1 npm run bench:all", | ||
"bench:10": "cross-env NUM_TESTS=10 npm run bench:all", | ||
"bench:100": "cross-env NUM_TESTS=100 npm run bench:all", | ||
"bench:1000": "cross-env NUM_TESTS=1000 npm run bench:all", | ||
"bench:10000": "cross-env NUM_TESTS=10000 npm run bench:all", | ||
"bench:all": "npm run bench:baseline-1 ; npm run bench:baseline-N ; npm run bench:fallback-1 ; npm run bench:fallback-N ; npm run bench:metadata-1 ; npm run bench:metadata-N ; true", | ||
"bench:metadata-1": "cross-env PRESET=metadata-1 jest", | ||
"bench:metadata-N": "cross-env PRESET=metadata-N jest", | ||
"bench:fallback-1": "cross-env PRESET=fallback-1 jest", | ||
"bench:fallback-N": "cross-env PRESET=fallback-N jest", | ||
"bench:baseline-1": "cross-env PRESET=baseline-1 jest", | ||
"bench:baseline-N": "cross-env PRESET=baseline-N jest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function generateTests() { | ||
const num = process.env.NUM_TESTS || '1'; | ||
return Array.from({length: +num}, () => { | ||
const a = randomInt(1, 100); | ||
const b = randomInt(1, 100); | ||
return [a, b, a + b]; | ||
}); | ||
} | ||
|
||
function randomInt(min, max) { | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
} | ||
|
||
module.exports = { | ||
generateTests, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters