Created
November 23, 2013 11:18
-
-
Save weizhu/7613409 to your computer and use it in GitHub Desktop.
Testing performance of fiber future
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
"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