-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.js
66 lines (55 loc) · 1.09 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var Bench = require('benchmark')
var app = require('./index')()
app
.set('one', 1)
.set('two', 2)
.set('three', 3)
.set('four', 4)
.set('five', 5)
.def('onedep', function(one) {
return one
})
.def('fivedeps', function(one, two, three, four, five) {
return one
})
.def('a', function() {
return 'a'
})
.def('b', function() {
return 'b'
})
.def('ab', function(a, b) {
return a + b
})
.def('async', function(two, done) {
done(null, two)
})
.def('bone', function(b, one) {
return b + one
})
.def('computation', function(bone, async, ab, done) {
done(null, bone + async + ab)
})
var fn = app.fn(function(a, b, cb) {
this.a = a
this.b = b
this.eval('ab', cb)
})
function noop() {}
var suite = new Bench.Suite
suite.add('1 dep', function() {
app.run().eval('onedep', noop)
})
suite.add('5 deps', function() {
app.run().eval('fivedeps', noop)
})
suite.add('computation', function() {
app.run().eval('computation', noop)
})
suite.add('function', function() {
fn('A', 'B', noop)
})
suite.on('cycle', function(ev, bench) {
console.log(String(ev.target))
})
suite.run({async: true})