git ssb

2+

Dominic / pull-stream



Commit a3f9653f439c7ec2c546a057c62e37f16790164d

benchmark 3 different ways to create a pull-stream pipeline

Dominic Tarr committed on 3/22/2016, 11:02:09 PM
Parent: e56a938dfb62ea6c992a1ad5a0fe44edd35e2ac8

Files changed

benchmarks/node-streams.jsdeleted
benchmarks/pull.jsadded
benchmarks/node-streams.jsView
@@ -1,26 +1,0 @@
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 readPipeline (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-], 10000)
25-
26-run()
benchmarks/pull.jsView
@@ -1,0 +1,53 @@
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+

Built with git-ssb-web