-
-
Notifications
You must be signed in to change notification settings - Fork 35.8k
benchmark: add test runner hooks and options #63754
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
Open
luanmuniz
wants to merge
3
commits into
nodejs:main
Choose a base branch
from
luanmuniz:benchmark-test-runner-hooks-options
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+180
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,56 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const { finished } = require('node:stream/promises'); | ||
| const reporter = require('../fixtures/empty-test-reporter'); | ||
| const { | ||
| after, | ||
| afterEach, | ||
| before, | ||
| beforeEach, | ||
| describe, | ||
| it, | ||
| } = require('node:test'); | ||
|
|
||
| const bench = common.createBenchmark(main, { | ||
| n: [1, 10, 100, 1000], | ||
| hook: ['before', 'after', 'beforeEach', 'afterEach'], | ||
| }, { | ||
| // We don't want to test the reporter here. | ||
| flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'], | ||
| }); | ||
|
|
||
| const hookList = { | ||
| before: before, | ||
| after: after, | ||
| beforeEach: beforeEach, | ||
| afterEach: afterEach, | ||
| }; | ||
|
|
||
| function run(loopAmount, avoidV8Optimization, hookFn) { | ||
| for (let i = 0; i < loopAmount; i++) { | ||
| describe(`${i}`, () => { | ||
| hookFn(() => { | ||
| avoidV8Optimization = i; | ||
| }); | ||
|
|
||
| it(`${i}`, () => { | ||
| avoidV8Optimization = i; | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| return finished(reporter); | ||
| } | ||
|
|
||
| function main(params) { | ||
| // eslint-disable-next-line prefer-const | ||
| let avoidV8Optimization = 0; | ||
| const hookFn = hookList[params.hook]; | ||
|
|
||
| bench.start(); | ||
|
|
||
| run(params.n, avoidV8Optimization, hookFn).then(() => { | ||
| bench.end(params.n); | ||
| }); | ||
| } | ||
This file contains hidden or 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,124 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const { finished } = require('node:stream/promises'); | ||
| const reporter = require('../fixtures/empty-test-reporter'); | ||
| const { it } = require('node:test'); | ||
|
|
||
| const bench = common.createBenchmark(main, { | ||
| n: [1, 10, 100, 1000], | ||
| option: [ | ||
| 'none', | ||
| 'skip', | ||
| 'skip-with-message', | ||
| 'skip-method', | ||
| 'skip-method-with-message', | ||
| 'todo', | ||
| 'todo-with-message', | ||
| 'todo-method', | ||
| 'todo-method-with-message', | ||
| ], | ||
| }, { | ||
| // We don't want to test the reporter here. | ||
| flags: ['--test-reporter=./benchmark/fixtures/empty-test-reporter.js'], | ||
| }); | ||
|
|
||
| const allTests = { | ||
| 'none': (loopAmount, avoidV8Optimization) => { | ||
| for (let i = 0; i < loopAmount; i++) { | ||
| it(`${i}`, () => { | ||
| avoidV8Optimization = i; | ||
| }); | ||
| } | ||
|
|
||
| return finished(reporter); | ||
| }, | ||
| 'skip': (loopAmount) => { | ||
| for (let i = 0; i < loopAmount; i++) { | ||
| it(`${i}`, { skip: true }, () => { | ||
| throw new Error('This test should not run.'); | ||
| }); | ||
| } | ||
|
|
||
| return finished(reporter); | ||
| }, | ||
| 'skip-with-message': (loopAmount) => { | ||
| for (let i = 0; i < loopAmount; i++) { | ||
| it(`${i}`, { skip: 'skip reason' }, () => { | ||
| throw new Error('This test should not run.'); | ||
| }); | ||
| } | ||
|
|
||
| return finished(reporter); | ||
| }, | ||
| 'skip-method': (loopAmount, avoidV8Optimization) => { | ||
| for (let i = 0; i < loopAmount; i++) { | ||
| it(`${i}`, (t) => { | ||
| avoidV8Optimization = i; | ||
| t.skip(); | ||
| }); | ||
| } | ||
|
|
||
| return finished(reporter); | ||
| }, | ||
| 'skip-method-with-message': (loopAmount, avoidV8Optimization) => { | ||
| for (let i = 0; i < loopAmount; i++) { | ||
| it(`${i}`, (t) => { | ||
| avoidV8Optimization = i; | ||
| t.skip('skip reason'); | ||
| }); | ||
| } | ||
|
|
||
| return finished(reporter); | ||
| }, | ||
| 'todo': (loopAmount, avoidV8Optimization) => { | ||
| for (let i = 0; i < loopAmount; i++) { | ||
| it(`${i}`, { todo: true }, () => { | ||
| avoidV8Optimization = i; | ||
| }); | ||
| } | ||
|
|
||
| return finished(reporter); | ||
| }, | ||
| 'todo-with-message': (loopAmount, avoidV8Optimization) => { | ||
| for (let i = 0; i < loopAmount; i++) { | ||
| it(`${i}`, { todo: 'todo reason' }, () => { | ||
| avoidV8Optimization = i; | ||
| }); | ||
| } | ||
|
|
||
| return finished(reporter); | ||
| }, | ||
| 'todo-method': (loopAmount, avoidV8Optimization) => { | ||
| for (let i = 0; i < loopAmount; i++) { | ||
| it(`${i}`, (t) => { | ||
| avoidV8Optimization = i; | ||
| t.todo(); | ||
| }); | ||
| } | ||
|
|
||
| return finished(reporter); | ||
| }, | ||
| 'todo-method-with-message': (loopAmount, avoidV8Optimization) => { | ||
| for (let i = 0; i < loopAmount; i++) { | ||
| it(`${i}`, (t) => { | ||
| avoidV8Optimization = i; | ||
| t.todo('todo reason'); | ||
| }); | ||
| } | ||
|
|
||
| return finished(reporter); | ||
| }, | ||
| }; | ||
|
|
||
| function main({ n, option }) { | ||
| // eslint-disable-next-line prefer-const | ||
| let avoidV8Optimization = 0; | ||
| const runOption = allTests[option]; | ||
|
|
||
| bench.start(); | ||
|
|
||
| runOption(n, avoidV8Optimization).then(() => { | ||
| bench.end(n); | ||
| }); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 0 and why let?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is
letbecause we rewrite the values through the benchmark, and there is no particular reason to be 0, just didn't want to leave it undefined, and the original value of the variable shouldn't have an impact on this.To be 100% honest, I don't quite understand the mechanics for this. I never dug into v8 optimizations before. The variable is there because I decided to follow the existing patterns inside this particular folder.
But please check this reference link and this for the comment that originally introduced this specific variable (Seems like the link is not working 100%, opening the discussion so just crtl+f for
benchmark/test_runner/global-concurrent-tests.jsand there should be a resolved review from H4ad with the reference)Obs: I just realized the hooks are noops, and given that this variable works as described, I shouldn't have a noop there, so I'm pushing code so the hooks also have minimal execution within the function. Thanks for calling my attention to this.