Created
January 19, 2015 05:19
-
-
Save poying/3ddc8cd38ef5c322c713 to your computer and use it in GitHub Desktop.
try-catch, domain.run
This file contains hidden or 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
'use strict'; | |
var domain = require('domain'); | |
var EventEmitter = require('events').EventEmitter; | |
var Bench = require('async-bench'); | |
console.log(); | |
Bench() | |
.compare(tryCatch_) | |
.compare(domain_) | |
.times([100, 1000, 10000, 1000000]) | |
.end(); | |
function tryCatch_(cb) { | |
try { | |
throw new Error('test'); | |
} catch (e) {} | |
cb(); | |
} | |
function domain_(cb) { | |
var d = domain.create(); | |
d.once('error', cb); | |
d.run(function () { | |
throw new Error('test'); | |
}); | |
} |
Author
poying
commented
Jan 19, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment