Spaces:
Running
Running
File size: 1,195 Bytes
d8f0e51 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
'use strict'
const max = 1000000
const fastqueue = require('./')(worker, 1)
const { promisify } = require('util')
const immediate = promisify(setImmediate)
const qPromise = require('./').promise(immediate, 1)
const async = require('async')
const neo = require('neo-async')
const asyncqueue = async.queue(worker, 1)
const neoqueue = neo.queue(worker, 1)
function bench (func, done) {
const key = max + '*' + func.name
let count = -1
console.time(key)
end()
function end () {
if (++count < max) {
func(end)
} else {
console.timeEnd(key)
if (done) {
done()
}
}
}
}
function benchFastQ (done) {
fastqueue.push(42, done)
}
function benchAsyncQueue (done) {
asyncqueue.push(42, done)
}
function benchNeoQueue (done) {
neoqueue.push(42, done)
}
function worker (arg, cb) {
setImmediate(cb)
}
function benchSetImmediate (cb) {
worker(42, cb)
}
function benchFastQPromise (done) {
qPromise.push(42).then(function () { done() }, done)
}
function runBench (done) {
async.eachSeries([
benchSetImmediate,
benchFastQ,
benchNeoQueue,
benchAsyncQueue,
benchFastQPromise
], bench, done)
}
runBench(runBench)
|