summaryrefslogtreecommitdiff
path: root/benchmark/misc
diff options
context:
space:
mode:
authormicnic <micnic90@gmail.com>2014-11-29 14:50:29 +0200
committerRod Vagg <rod@vagg.org>2014-12-12 12:14:11 +1100
commit8c69d7bed47358d5ef4a5226f60e97145300b49b (patch)
tree5ece105e77fc3367d112eb62091d521c58ecb24b /benchmark/misc
parent41ec1a7d5bdc1a467fde73a4440a7aad1fe7401c (diff)
downloadandroid-node-v8-8c69d7bed47358d5ef4a5226f60e97145300b49b.tar.gz
android-node-v8-8c69d7bed47358d5ef4a5226f60e97145300b49b.tar.bz2
android-node-v8-8c69d7bed47358d5ef4a5226f60e97145300b49b.zip
domain: forward args to .run(fn)
Adds the feature to define arguments for the function called in domain.run(), this is supposed to be useful when a function is called from another context and some values from the current context are needed as arguments, it's similar to the callback from setTimeout or setInterval. PR-URL: https://github.com/iojs/io.js/pull/15 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'benchmark/misc')
-rw-r--r--benchmark/misc/domain-fn-args.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/benchmark/misc/domain-fn-args.js b/benchmark/misc/domain-fn-args.js
new file mode 100644
index 0000000000..36e9e90029
--- /dev/null
+++ b/benchmark/misc/domain-fn-args.js
@@ -0,0 +1,43 @@
+var common = require('../common.js');
+var domain = require('domain');
+
+var bench = common.createBenchmark(main, {
+ arguments: [0, 1, 2, 3],
+ n: [10]
+});
+
+var bdomain = domain.create();
+var gargs = [1, 2, 3];
+
+function main(conf) {
+
+ var args, ret, n = +conf.n;
+ var arguments = gargs.slice(0, conf.arguments);
+ bench.start();
+
+ bdomain.enter();
+ for (var i = 0; i < n; i++) {
+ if (arguments.length >= 2) {
+ args = Array.prototype.slice.call(arguments, 1);
+ ret = fn.apply(this, args);
+ } else {
+ ret = fn.call(this);
+ }
+ }
+ bdomain.exit();
+
+ bench.end(n);
+}
+
+function fn(a, b, c) {
+ if (!a)
+ a = 1;
+
+ if (!b)
+ b = 2;
+
+ if (!c)
+ c = 3;
+
+ return a + b + c;
+} \ No newline at end of file