summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2017-01-14 19:43:08 -0800
committerJames M Snell <jasnell@gmail.com>2017-01-18 08:26:57 -0800
commit030dd14793da2aa1c252e38d33abb37570f8ee8a (patch)
treed221d4c6dba3c3e28cb86c98f301a54e4ded6096 /benchmark
parent90a2bb53b0eebf8f2fd6d3a3342b1c3d45a1bfb5 (diff)
downloadandroid-node-v8-030dd14793da2aa1c252e38d33abb37570f8ee8a.tar.gz
android-node-v8-030dd14793da2aa1c252e38d33abb37570f8ee8a.tar.bz2
android-node-v8-030dd14793da2aa1c252e38d33abb37570f8ee8a.zip
benchmark: add benchmark for vm.runIn*()
Introduce benchmarks for vm.runInContext() and vm.runInThisContext(). PR-URL: https://github.com/nodejs/node/pull/10816 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Brian White <mscdex@mscdex.net>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/vm/run-in-context.js32
-rw-r--r--benchmark/vm/run-in-this-context.js29
2 files changed, 61 insertions, 0 deletions
diff --git a/benchmark/vm/run-in-context.js b/benchmark/vm/run-in-context.js
new file mode 100644
index 0000000000..62ebe29146
--- /dev/null
+++ b/benchmark/vm/run-in-context.js
@@ -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;
+
+ 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);
+}
diff --git a/benchmark/vm/run-in-this-context.js b/benchmark/vm/run-in-this-context.js
new file mode 100644
index 0000000000..f66fd31a1a
--- /dev/null
+++ b/benchmark/vm/run-in-this-context.js
@@ -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);
+}