-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathacorn-benchmark.js
66 lines (60 loc) · 1.65 KB
/
acorn-benchmark.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
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const acorn = require("acorn");
const fs = require("fs");
const walk = require("acorn/dist/walk");
const payloads = [
{
name: "backbone-1.1.0.js",
options: { ecmaVersion: 5, sourceType: "script" }
},
{
name: "jquery-3.2.1.js",
options: { ecmaVersion: 5, sourceType: "script" }
},
{
name: "lodash.core-4.17.4.js",
options: { ecmaVersion: 5, sourceType: "script" }
},
{
name: "preact-8.2.5.js",
options: { ecmaVersion: 5, sourceType: "script" }
},
{
name: "redux.min-3.7.2.js",
options: { ecmaVersion: 5, sourceType: "script" }
},
{
name: "speedometer-es2015-test-2.0.js",
options: { ecmaVersion: 6, sourceType: "script" }
},
{
name: "underscore-1.8.3.js",
options: { ecmaVersion: 5, sourceType: "script" }
},
{
name: "vue.runtime.esm-nobuble-2.4.4.js",
options: { ecmaVersion: 7, sourceType: "module" }
}
].map(({ name, options }) => ({
payload: fs.readFileSync(`third_party/${name}`, "utf8"),
options: Object.assign(options, { locations: true }, { ranges: true })
}));
module.exports = {
name: "acorn",
fn() {
return payloads.map(({ payload, options }) => {
let count = 0;
// Test the tokenizer by counting the resulting tokens.
for (const token of acorn.tokenizer(payload, options)) {
count++;
}
// Test the parser.
const ast = acorn.parse(payload, options);
// Test the AST walker.
walk.full(ast, node => count++);
return count;
});
}
};