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
45 lines (40 loc) · 1.32 KB
/
benchmark.js
File metadata and controls
45 lines (40 loc) · 1.32 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
/* eslint no-console: 0 */
import path from "path";
import klawSync from "klaw-sync";
import fs from "fs";
import * as npmparser from "java-parser-npm";
import { performance } from "perf_hooks";
import url from "url";
import * as currentparser from "../../packages/java-parser/src/index.js";
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
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 = javaSampleFiles.map(fileDesc => {
const currJavaFileString = fs.readFileSync(fileDesc.path, "utf8");
const relativePath = path.relative(__dirname, fileDesc.path);
return { path: relativePath, text: currJavaFileString };
});
function benchmarkParser(parser) {
const start = performance.now();
javaPathAndText.forEach(javaText => {
try {
parser(javaText.text);
} catch (e) {
console.log(e);
}
});
const end = performance.now();
return `${end - start}ms`;
}
for (let i = 0; i < 3; i++) {
console.log(`NPM Java Parser (${benchmarkParser(npmparser.parse)})`);
console.log(
`Local Repository Java Parser (${benchmarkParser(currentparser.parse)})`
);
}