Skip to content

Instantly share code, notes, and snippets.

@chrisyip
Created Jul 14, 2017
Embed
What would you like to do?
async vs co
'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)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment