-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #15 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
- Loading branch information
Showing
4 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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,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; | ||
} |
This file contains 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
This file contains 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
This file contains 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