Last change
on this file since bdd6491 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 |
|
---|
3 | const max = 1000000
|
---|
4 | const fastqueue = require('./')(worker, 1)
|
---|
5 | const { promisify } = require('util')
|
---|
6 | const immediate = promisify(setImmediate)
|
---|
7 | const qPromise = require('./').promise(immediate, 1)
|
---|
8 | const async = require('async')
|
---|
9 | const neo = require('neo-async')
|
---|
10 | const asyncqueue = async.queue(worker, 1)
|
---|
11 | const neoqueue = neo.queue(worker, 1)
|
---|
12 |
|
---|
13 | function 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 |
|
---|
32 | function benchFastQ (done) {
|
---|
33 | fastqueue.push(42, done)
|
---|
34 | }
|
---|
35 |
|
---|
36 | function benchAsyncQueue (done) {
|
---|
37 | asyncqueue.push(42, done)
|
---|
38 | }
|
---|
39 |
|
---|
40 | function benchNeoQueue (done) {
|
---|
41 | neoqueue.push(42, done)
|
---|
42 | }
|
---|
43 |
|
---|
44 | function worker (arg, cb) {
|
---|
45 | setImmediate(cb)
|
---|
46 | }
|
---|
47 |
|
---|
48 | function benchSetImmediate (cb) {
|
---|
49 | worker(42, cb)
|
---|
50 | }
|
---|
51 |
|
---|
52 | function benchFastQPromise (done) {
|
---|
53 | qPromise.push(42).then(function () { done() }, done)
|
---|
54 | }
|
---|
55 |
|
---|
56 | function runBench (done) {
|
---|
57 | async.eachSeries([
|
---|
58 | benchSetImmediate,
|
---|
59 | benchFastQ,
|
---|
60 | benchNeoQueue,
|
---|
61 | benchAsyncQueue,
|
---|
62 | benchFastQPromise
|
---|
63 | ], bench, done)
|
---|
64 | }
|
---|
65 |
|
---|
66 | runBench(runBench)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.