Skip to content

Instantly share code, notes, and snippets.

@weizhu
Created November 23, 2013 11:18
Show Gist options
  • Save weizhu/7613409 to your computer and use it in GitHub Desktop.
Save weizhu/7613409 to your computer and use it in GitHub Desktop.
Testing performance of fiber future
"use strict";
var Fiber = require('fibers');
var Future = require('fibers/future'), wait = Future.wait;
var getByIdCb= function(id, cb) {
cb(null, 'foo');
}
var getById = Future.wrap(getByIdCb);
var testSync = function() {
Fiber(function() {
try {
var places=[];
console.time('step1');
// Load places
for (var i=0; i < 2000; i++) {
places.push(getById(i));
}
console.timeEnd('step1');
console.time('step2');
wait(places);
console.timeEnd('step2');
} catch (e) {
console.error(e.stack);
}
}).run();
}
testSync();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment