-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbench.js
47 lines (45 loc) · 1.11 KB
/
bench.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import Benchmark from 'benchmark'
import erre from './index.js'
const suite = new Benchmark.Suite(),
noop = function() {}
suite
.add('create/destroy', function() {
const stream = erre()
stream.on.value(function() {
stream.end()
})
stream.push('foo')
})
.add('stress', function() {
const stream = erre(noop, noop, noop, noop)
stream.on.value(noop.bind(null))
stream.on.end(noop)
stream.on.value(noop.bind(null))
stream.on.error(noop.bind(null))
stream.push('2')
stream.push(undefined)
stream.push(null)
stream.push({})
stream.push('bar')
stream.push(Infinity)
stream.push(NaN)
stream.end()
})
.add('fork', function() {
const stream = erre(noop, noop, noop, noop)
stream.on.value(noop.bind(null))
stream.on.value(noop.bind(null))
stream.push('2')
const fork = stream.fork()
stream.end()
fork.on.value(noop.bind(null))
fork.push('foo')
fork.end()
})
.on('cycle', function(event) {
console.log(String(event.target))
})
.on('error', function(e) {
console.log(e.target.error)
})
.run({async: true})