-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
timers: clean up for readability #17279
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Remove micro-optimizations that no longer yield any benefits, restructure timers & immediates to be a bit more straightforward. Adjust timers benchmarks to run long enough to offer meaningful data.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,22 +2,26 @@ | |
| const common = require('../common.js'); | ||
|
|
||
| const bench = common.createBenchmark(main, { | ||
| thousands: [500], | ||
| millions: [10], | ||
| }); | ||
|
|
||
| function main(conf) { | ||
| const iterations = +conf.thousands * 1e3; | ||
| var count = 0; | ||
| const iterations = +conf.millions * 1e6; | ||
|
|
||
| // Function tracking on the hidden class in V8 can cause misleading | ||
| // results in this benchmark if only a single function is used — | ||
| // alternate between two functions for a fairer benchmark | ||
|
|
||
| function cb() {} | ||
| function cb2() {} | ||
|
|
||
| process.on('exit', function() { | ||
| bench.end(iterations / 1e6); | ||
| }); | ||
|
|
||
| for (var i = 0; i < iterations; i++) { | ||
| setTimeout(cb, 1); | ||
| setTimeout(i % 2 ? cb : cb2, 1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: add a comment that this sets up
I wish we could exclude steps 2-4 from the measurement 🤔
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a comment. |
||
| } | ||
|
|
||
| bench.start(); | ||
|
|
||
| function cb() { | ||
| count++; | ||
| if (count === iterations) | ||
| bench.end(iterations / 1e3); | ||
| } | ||
| } | ||
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.
Not loving this... It's async, so it could add noise, also having the callbacks have side effects improves the chances they are not optimized away.
I'd rather have duplicate
cb()code, or havecbjustcount++andcb2test for exit.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.
Addressed with duplicate code.