-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
benchmark: add benchmark utility for Error instance #61180
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
3b40faf
5fcf423
9de3f6f
c4aaa5d
23955ed
f2e53f1
6b26012
8c79e29
a0f0062
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
|
|
||
| const args = { | ||
| true: new Error('test'), | ||
| falsePrimitive: 42, | ||
| falseObject: { foo: 'bar' }, | ||
| }; | ||
|
|
||
| const bench = common.createBenchmark( | ||
| main, | ||
| { | ||
| argument: ['true', 'falsePrimitive', 'falseObject'], | ||
| version: ['native', 'js'], | ||
| n: [1e6], | ||
| }, | ||
| { | ||
| flags: ['--expose-internals', '--no-warnings'], | ||
| }, | ||
| ); | ||
|
|
||
| function main({ argument, version, n }) { | ||
| const util = common.binding('util'); | ||
| const types = require('internal/util/types'); | ||
|
|
||
| const func = { native: util, js: types }[version].isNativeError; | ||
|
|
||
| const testArgs = [args[argument], args[argument], args[argument]]; | ||
|
||
| let sum = 0; | ||
|
|
||
| bench.start(); | ||
| for (let iteration = 0; iteration < n; iteration++) { | ||
| const testArg = testArgs[iteration % 3]; | ||
| sum += func(testArg) ? 1 : 0; | ||
| } | ||
| bench.end(n); | ||
| if (sum < 0) console.log(sum); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Isn't recently deprecated?
node/doc/api/deprecations.md
Line 4283 in 20bf328
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 deprecated but still supported - we should still not regress on stable releases and this change ensures that @RafaelGSS
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.
But, what's the point of this benchmark? I mean, if we see util/isNativeError is slower, what it means afterall? Which API will be directly impacted besides the deprecated API?
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.
This comparison ensures that existing users will not experience performance drops or unexpected slowdowns until the API is completely removed. It also aims to provide a reference for future changes or alternatives.