Permalink
Browse files

Added "when" implementation to benchmarks

  • Loading branch information...
1 parent 822ece2 commit c969c294420ab014a3bfba6773324b48d139e944 @medikoo committed Oct 1, 2012
Showing with 82 additions and 15 deletions.
  1. +15 −13 README.md
  2. +34 −1 benchmark/concurrent.js
  3. +33 −1 benchmark/one-after-another.js
View
@@ -635,22 +635,24 @@ _Example output taken under Node v0.8.9 on 2008 MBP._
```
Promise overhead (calling one after another) x10000:
-1: 461ms Base (plain Node.js lstat call)
-2: 636ms Deferred: Dedicated wrapper
-3: 714ms Deferred: Promisify (generic wrapper)
-4: 995ms jQuery.Deferred: Dedicated wrapper
-5: 3312ms Q: Dedicated wrapper
-6: 7035ms Q: nbind (generic wrapper)
+1: 460ms Base (plain Node.js lstat call)
+2: 644ms Deferred: Dedicated wrapper
+3: 719ms Deferred: Promisify (generic wrapper)
+4: 991ms jQuery.Deferred: Dedicated wrapper
+5: 1171ms When: Dedicated wrapper
+6: 3344ms Q: Dedicated wrapper
+7: 7027ms Q: nbind (generic wrapper)
Promise overhead (concurrent calls) x10000:
-1: 300ms Base (plain Node.js lstat call)
-2: 535ms Deferred: Dedicated wrapper
-3: 622ms Deferred: Promisify (generic wrapper)
-4: 672ms Deferred: Map + Promisify
-5: 1022ms jQuery.Deferred: Dedicated wrapper
-6: 2911ms Q: Dedicated wrapper
-7: 5317ms Q: nbind (generic wrapper)
+1: 303ms Base (plain Node.js lstat call)
+2: 533ms Deferred: Dedicated wrapper
+3: 607ms Deferred: Promisify (generic wrapper)
+4: 712ms Deferred: Map + Promisify
+5: 1074ms jQuery.Deferred: Dedicated wrapper
+6: 1616ms when: Dedicated wrapper
+7: 2994ms Q: Dedicated wrapper
+8: 5214ms Q: nbind (generic wrapper)
```
## Tests [![Build Status](https://secure.travis-ci.org/medikoo/deferred.png?branch=master)](https://secure.travis-ci.org/medikoo/deferred)
View
@@ -3,7 +3,7 @@
// Benchmark comparing performance of promise setups (concurrent)
// To run it, do following in package path:
//
-// $ npm install Q jquery
+// $ npm install Q jquery when
// $ node benchmark/concurrent.js
var generate = require('es5-ext/lib/Array/generate')
@@ -12,6 +12,7 @@ var generate = require('es5-ext/lib/Array/generate')
, lstat = require('fs').lstat
, Q = require('Q')
, jqDeferred = require('jquery').Deferred
+ , when = require('when')
, deferred = require('../lib')
, now = Date.now
@@ -163,6 +164,38 @@ tests = [function () {
while (j--) {
self();
}
+}, function () {
+ var i = count, j = count, dlstat;
+
+ dlstat = function (path) {
+ var def = when.defer();
+ lstat(path, function (err, stats) {
+ if (err) {
+ def.reject(err);
+ } else {
+ def.resolve(stats);
+ }
+ });
+ return def;
+ };
+
+ self = function () {
+ dlstat(__filename).then(function () {
+ if (!--i) {
+ data["When: Dedicated wrapper"] = now() - time;
+ nextTick(next);
+ }
+ }, function (e) {
+ nextTick(function () {
+ throw e;
+ });
+ });
+ };
+
+ time = now();
+ while (j--) {
+ self();
+ }
}];
next = function () {
@@ -4,14 +4,15 @@
// (one by after another)
// To run it, do following in package path:
//
-// $ npm install Q jquery
+// $ npm install Q jquery when
// $ node benchmark/one-after-another.js
var forEach = require('es5-ext/lib/Object/for-each')
, pad = require('es5-ext/lib/String/prototype/pad')
, lstat = require('fs').lstat
, Q = require('Q')
, jqDeferred = require('jquery').Deferred
+ , when = require('when')
, deferred = require('../lib')
, now = Date.now
@@ -151,6 +152,37 @@ tests = [function () {
};
time = now();
self();
+}, function () {
+ var i = count, j = count, dlstat;
+
+ dlstat = function (path) {
+ var def = when.defer();
+ lstat(path, function (err, stats) {
+ if (err) {
+ def.reject(err);
+ } else {
+ def.resolve(stats);
+ }
+ });
+ return def;
+ };
+
+ self = function () {
+ dlstat(__filename).then(function (stats) {
+ if (--i) {
+ self(stats);
+ } else {
+ data["When: Dedicated wrapper"] = now() - time;
+ nextTick(next);
+ }
+ }, function (e) {
+ nextTick(function () {
+ throw e;
+ });
+ });
+ };
+ time = now();
+ self();
}];
next = function () {

0 comments on commit c969c29

Please sign in to comment.