Files: 8c0347d8e7f88171cd4c45eec22b42c5c7332fac / benchmarks / pull.js
1307 bytesRaw
1 | const bench = require('fastbench') |
2 | const pull = require('../') |
3 | |
4 | const values = [ |
5 | JSON.stringify({ hello: 'world' }), |
6 | JSON.stringify({ foo: 'bar' }), |
7 | JSON.stringify({ bin: 'baz' }) |
8 | ] |
9 | |
10 | const run = bench([ |
11 | function pull3 (done) { |
12 | const source = pull.values(values) |
13 | const through = pull.asyncMap(function (val, done) { |
14 | const json = JSON.parse(val) |
15 | done(null, json) |
16 | }) |
17 | |
18 | const sink = pull.collect(function (err, array) { |
19 | if (err) return console.error(err) |
20 | setImmediate(done) |
21 | }) |
22 | pull(source, through, sink) |
23 | }, |
24 | function pull_compose (done) { |
25 | const source = pull.values(values) |
26 | const through = pull.asyncMap(function (val, done) { |
27 | const json = JSON.parse(val) |
28 | done(null, json) |
29 | }) |
30 | |
31 | const sink = pull.collect(function (err, array) { |
32 | if (err) return console.error(err) |
33 | setImmediate(done) |
34 | }) |
35 | pull(source, pull(through, sink)) |
36 | }, |
37 | function pull_chain (done) { |
38 | const source = pull.values(values) |
39 | const through = pull.asyncMap(function (val, done) { |
40 | const json = JSON.parse(val) |
41 | done(null, json) |
42 | }) |
43 | |
44 | const sink = pull.collect(function (err, array) { |
45 | if (err) return console.error(err) |
46 | setImmediate(done) |
47 | }) |
48 | pull(pull(source, through), sink) |
49 | } |
50 | ], 100000) |
51 | |
52 | run() |
53 | |
54 |
Built with git-ssb-web