-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Closed
mertcanaltin
wants to merge
9
commits into
nodejs:main
from
mertcanaltin:mert/create/benchmark/isNativeError
Closed
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3b40faf
benchmark: add benchmark utility for isNativeError function
mertcanaltin 5fcf423
repair benchmark
mertcanaltin 9de3f6f
refine test arguments and measure elapsed time in isNativeError bench…
mertcanaltin c4aaa5d
simplify isNativeError test arguments and remove performance logging
mertcanaltin 23955ed
store result of isNativeError function for validation
mertcanaltin f2e53f1
add benchmark utility for isError function
mertcanaltin 6b26012
refactor benchmark utility for isError function to improve readability
mertcanaltin 8c79e29
add benchmark utility for isNativeError function
mertcanaltin a0f0062
Merge branch 'main' into mert/create/benchmark/isNativeError
mertcanaltin 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,35 @@ | ||
| '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 arg = args[argument]; | ||
|
|
||
| bench.start(); | ||
| for (let iteration = 0; iteration < n; iteration++) { | ||
| func(arg); | ||
|
Member
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. This is likely being optimized.
Member
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. Hi, I tried to fix this by using more arguments and variable arguments. 5fcf423
mertcanaltin marked this conversation as resolved.
Outdated
|
||
| } | ||
| bench.end(n); | ||
| } | ||
Oops, something went wrong.
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.
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.