index.js
1.51 KB
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
67
68
69
70
71
var bench = require('nanobench')
var src = require('fs').readFileSync(require.resolve('acorn'))
var parse = require('acorn').parse
var astw = require('astw')
var eswalk = require('estree-walk')
var eswalker = require('estree-walker')
var dash = require('../')
bench('astw', function (b) {
var ast = parse(src)
b.start()
var i = 0
astw(ast)(function (node) { i++ })
b.end('walked ' + i + ' nodes')
})
bench('estree-walk', function (b) {
var ast = parse(src)
b.start()
var i = 0
eswalk(ast, function (node) { i++ })
b.end('walked ' + i + ' nodes')
})
bench('estree-walk steps', function (b) {
var ast = parse(src)
b.start()
var i = 0
for (var q = [ast], node; (node = q.pop()); eswalk.step(node, q)) {
i++
}
b.end('walked ' + i + ' nodes')
})
bench('dash-ast', function (b) {
var ast = parse(src)
b.start()
var i = 0
dash(ast, function (node) { i++ })
b.end('walked ' + i + ' nodes')
})
bench('dash-ast with .parent', function (b) {
var ast = parse(src)
b.start()
var i = 0
dash.withParent(ast, function (node) { i++ })
b.end('walked ' + i + ' nodes')
})
bench('dash-ast with enter/leave', function (b) {
var ast = parse(src)
b.start()
var i = 0
var j = 0
dash(ast, {
enter: function (node) { i++ },
leave: function (node) { j++ }
})
b.end('walked ' + [i, j] + ' nodes')
})
bench('estree-walker', function (b) {
var ast = parse(src)
b.start()
var i = 0
eswalker.walk(ast, {
enter: function (node) { i++ }
})
b.end('walked ' + i + ' nodes')
})