Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade to Chevrotain 11 #616

Merged
merged 3 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ env:
es6: true
node: true
parserOptions:
ecmaVersion: 2018
ecmaVersion: 2020
sourceType: module
rules:
no-fallthrough: off
curly: error
Expand Down
56 changes: 0 additions & 56 deletions benchmark/java-parser/benchmark-demo.js

This file was deleted.

50 changes: 19 additions & 31 deletions benchmark/java-parser/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
/* 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");
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"
Expand All @@ -26,32 +17,29 @@ const javaSampleFiles = sampleFiles.filter(fileDesc =>
fileDesc.path.endsWith(".java")
);

const javaPathAndText = _.map(javaSampleFiles, fileDesc => {
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) {
_.forEach(javaPathAndText, javaText => {
const start = performance.now();
javaPathAndText.forEach(javaText => {
try {
parser(javaText.text);
} catch (e) {
console.log(e);
}
});
const end = performance.now();
return `${end - start}ms`;
}

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();
for (let i = 0; i < 3; i++) {
console.log(`NPM Java Parser (${benchmarkParser(npmparser.parse)})`);
console.log(
`Local Repository Java Parser (${benchmarkParser(currentparser.parse)})`
);
}
5 changes: 3 additions & 2 deletions benchmark/java-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "1.0.0",
"private": true,
"description": "Benchmark for comparing Parsers",
"main": "benchmark.js",
"type": "module",
"exports": "./benchmark.js",
"scripts": {
"start": "node benchmark.js"
},
Expand All @@ -18,6 +19,6 @@
},
"homepage": "https://github.com/jhipster/prettier-java#readme",
"devDependencies": {
"npm-install-version": "^6.0.2"
"java-parser-npm": "npm:java-parser@2.0.5"
}
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
]
},
"devDependencies": {
"benchmark": "^2.1.4",
"chai": "^4.3.7",
"eslint": "8.28.0",
"eslint-config-google": "0.14.0",
Expand All @@ -42,8 +41,8 @@
"lint-staged": "13.0.4",
"mocha": "^10.1.0",
"nyc": "^15.1.0",
"prettier": "2.8.0",
"sinon": "^9.2.1"
"prettier": "3.0.3",
"sinon": "^17.0.1"
},
"dependencies": {}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/java-parser/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ docs
samples
scripts
test
.mocharc.js
.mocharc.cjs
diagrams.html
*.log
Loading