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 | /* eslint no-console: "off" */
|
---|
2 |
|
---|
3 | var asynckit = require('./')
|
---|
4 | , async = require('async')
|
---|
5 | , assert = require('assert')
|
---|
6 | , expected = 0
|
---|
7 | ;
|
---|
8 |
|
---|
9 | var Benchmark = require('benchmark');
|
---|
10 | var suite = new Benchmark.Suite;
|
---|
11 |
|
---|
12 | var source = [];
|
---|
13 | for (var z = 1; z < 100; z++)
|
---|
14 | {
|
---|
15 | source.push(z);
|
---|
16 | expected += z;
|
---|
17 | }
|
---|
18 |
|
---|
19 | suite
|
---|
20 | // add tests
|
---|
21 |
|
---|
22 | .add('async.map', function(deferred)
|
---|
23 | {
|
---|
24 | var total = 0;
|
---|
25 |
|
---|
26 | async.map(source,
|
---|
27 | function(i, cb)
|
---|
28 | {
|
---|
29 | setImmediate(function()
|
---|
30 | {
|
---|
31 | total += i;
|
---|
32 | cb(null, total);
|
---|
33 | });
|
---|
34 | },
|
---|
35 | function(err, result)
|
---|
36 | {
|
---|
37 | assert.ifError(err);
|
---|
38 | assert.equal(result[result.length - 1], expected);
|
---|
39 | deferred.resolve();
|
---|
40 | });
|
---|
41 | }, {'defer': true})
|
---|
42 |
|
---|
43 |
|
---|
44 | .add('asynckit.parallel', function(deferred)
|
---|
45 | {
|
---|
46 | var total = 0;
|
---|
47 |
|
---|
48 | asynckit.parallel(source,
|
---|
49 | function(i, cb)
|
---|
50 | {
|
---|
51 | setImmediate(function()
|
---|
52 | {
|
---|
53 | total += i;
|
---|
54 | cb(null, total);
|
---|
55 | });
|
---|
56 | },
|
---|
57 | function(err, result)
|
---|
58 | {
|
---|
59 | assert.ifError(err);
|
---|
60 | assert.equal(result[result.length - 1], expected);
|
---|
61 | deferred.resolve();
|
---|
62 | });
|
---|
63 | }, {'defer': true})
|
---|
64 |
|
---|
65 |
|
---|
66 | // add listeners
|
---|
67 | .on('cycle', function(ev)
|
---|
68 | {
|
---|
69 | console.log(String(ev.target));
|
---|
70 | })
|
---|
71 | .on('complete', function()
|
---|
72 | {
|
---|
73 | console.log('Fastest is ' + this.filter('fastest').map('name'));
|
---|
74 | })
|
---|
75 | // run async
|
---|
76 | .run({ 'async': true });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.