-
Notifications
You must be signed in to change notification settings - Fork 30k
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
vm: improve performance of vm.runIn*() #10816
Changes from all commits
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,32 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1], | ||
breakOnSigint: [0, 1], | ||
withSigintListener: [0, 1] | ||
}); | ||
|
||
const vm = require('vm'); | ||
|
||
function main(conf) { | ||
const n = +conf.n; | ||
const options = conf.breakOnSigint ? {breakOnSigint: true} : {}; | ||
const withSigintListener = !!conf.withSigintListener; | ||
|
||
process.removeAllListeners('SIGINT'); | ||
if (withSigintListener) | ||
process.on('SIGINT', () => {}); | ||
|
||
var i = 0; | ||
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. Out of curiosity, is there a reason you define 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 used |
||
|
||
const contextifiedSandbox = vm.createContext(); | ||
|
||
common.v8ForceOptimization(vm.runInContext, | ||
'0', contextifiedSandbox, options); | ||
bench.start(); | ||
for (; i < n; i++) | ||
vm.runInContext('0', contextifiedSandbox, options); | ||
bench.end(n); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1], | ||
breakOnSigint: [0, 1], | ||
withSigintListener: [0, 1] | ||
}); | ||
|
||
const vm = require('vm'); | ||
|
||
function main(conf) { | ||
const n = +conf.n; | ||
const options = conf.breakOnSigint ? {breakOnSigint: true} : {}; | ||
const withSigintListener = !!conf.withSigintListener; | ||
|
||
process.removeAllListeners('SIGINT'); | ||
if (withSigintListener) | ||
process.on('SIGINT', () => {}); | ||
|
||
var i = 0; | ||
|
||
common.v8ForceOptimization(vm.runInThisContext, '0', options); | ||
bench.start(); | ||
for (; i < n; i++) | ||
vm.runInThisContext('0', options); | ||
bench.end(n); | ||
} |
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.
Just a single iteration?
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.
Yeah, I had to bump up
n
considerably to get the benchmarks to run long enough for me to be comfortable with the results, but then again I find myself having to do that a lot with many of the other existing benchmarks ...