source: trip-planner-front/node_modules/fastq/bench.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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