Skip to content

Instantly share code, notes, and snippets.

@poying
Created January 19, 2015 05:19
Show Gist options
  • Save poying/3ddc8cd38ef5c322c713 to your computer and use it in GitHub Desktop.
Save poying/3ddc8cd38ef5c322c713 to your computer and use it in GitHub Desktop.
try-catch, domain.run
'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');
});
}
@poying
Copy link
Author

poying commented Jan 19, 2015

  100 times
   › tryCatch_: 2.68 ms
   › domain_: 7.97 ms

  1000 times
   › tryCatch_: 7 ms
   › domain_: 27 ms

  10000 times
   › tryCatch_: 52 ms
   › domain_: 143 ms

  1000000 times
   › tryCatch_: 4.51 s
   › domain_: 13 s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment