Created
July 14, 2017 04:20
-
-
Save chrisyip/22bb23b77069a49d06ab84981851592c to your computer and use it in GitHub Desktop.
Revisions
-
chrisyip created this gist
Jul 14, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ 'use strict' console.log('Using node %s', process.versions.node) function p () { return Promise.resolve('hello').then(s => `${s} world`) } const a = async function () { await p() } const co = require('co') const c = co.wrap(function * () { yield p() }) suite('async vs co', function () { bench('async', function (next) { const ps = [] for (let index = 0; index < 100; index++) { ps.push(a()) } Promise.all(ps).then(next, next) }) bench('co', function (next) { const ps = [] for (let index = 0; index < 100; index++) { ps.push(c()) } Promise.all(ps).then(next, next) }) })