forked from jhipster/prettier-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.js
More file actions
57 lines (50 loc) · 1.65 KB
/
benchmark.js
File metadata and controls
57 lines (50 loc) · 1.65 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
/* eslint no-console: 0 */
"use strict";
const path = require("path");
const klawSync = require("klaw-sync");
const _ = require("lodash");
const fs = require("fs");
const benchmark = require("benchmark");
const cp = require("child_process");
const niv = require("npm-install-version");
const version = cp
.execSync("npm show java-parser version")
.toString()
.replace("\n", "");
niv.install(`java-parser@${version}`);
const npmparser = require(`java-parser@${version}`);
const currentparser = require("../../packages/java-parser/src/index");
const samplesDir = path.resolve(
__dirname,
"../../packages/java-parser/samples/java-design-patterns/flux"
);
const sampleFiles = klawSync(samplesDir, { nodir: true });
const javaSampleFiles = sampleFiles.filter(fileDesc =>
fileDesc.path.endsWith(".java")
);
const javaPathAndText = _.map(javaSampleFiles, fileDesc => {
const currJavaFileString = fs.readFileSync(fileDesc.path, "utf8");
const relativePath = path.relative(__dirname, fileDesc.path);
return { path: relativePath, text: currJavaFileString };
});
function benchmarkParser(parser) {
_.forEach(javaPathAndText, javaText => {
try {
parser(javaText.text);
} catch (e) {
console.log(e);
}
});
}
new benchmark.Suite("Java parser benchmark", {
onStart: () => console.log(`Java parser benchmark`),
onCycle: event => console.log(String(event.target)),
onComplete: function () {
console.log("Fastest is " + this.filter("fastest").map("name"));
}
})
.add(`NPM Java Parser (v${version})`, () => benchmarkParser(npmparser.parse))
.add("Local Repository Java Parser", () =>
benchmarkParser(currentparser.parse)
)
.run();