-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
benchmark: util._extend vs object.assign
#7255
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
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common.js'); | ||
| const util = require('util'); | ||
| const v8 = require('v8'); | ||
|
|
||
| const bench = common.createBenchmark(main, { | ||
| type: ['util._extend', 'Object.assign', | ||
| 'util._extend', 'Object.assign'], | ||
|
||
| n: [10e4] | ||
| }); | ||
|
|
||
| function main(params) { | ||
|
||
| let fn; | ||
| const n = params.n | 0; | ||
| let v8command; | ||
|
|
||
| if (params.type == 'util._extend') { | ||
| fn = util._extend; | ||
| v8command = '%OptimizeFunctionOnNextCall(util._extend)'; | ||
|
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. I don't know exactly how
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. I think this is the right way. It will get |
||
|
|
||
| } else if (params.type == 'Object.assign') { | ||
| fn = Object.assign; | ||
| //Object.assign is built-in, cannot be optimized | ||
|
||
| v8command = ''; | ||
| } | ||
|
|
||
| // Force-optimize the method to test so that the benchmark doesn't | ||
| // get disrupted by the optimizer kicking in halfway through. | ||
| for (let i = 0; i < params.type.length * 10; i += 1) | ||
| fn({}, process.env); | ||
|
|
||
| v8.setFlagsFromString('--allow_natives_syntax'); | ||
| eval(v8command); | ||
|
|
||
| bench.start(); | ||
| for (let i = 0; i < n; i += 1) | ||
| fn({}, process.env); | ||
|
||
| bench.end(n); | ||
| } | ||
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.
I think these can be shortened down to just
extend(or_extend) andassign.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.
Done.