Skip to content

Commit af4f1d2

Browse files
authored
fix: update benchmark so it's buildable (#731)
- move files from .js to .mjs so they are usable as modules - shim __dirname using fileURLToPath - add a benchmark/README.md explaining the build process (such as it is) - update CONTRIBUTING.md to link to the new README.md - fix backslashes in CONTRIBUTING.md Fixes: #730
1 parent 56107fe commit af4f1d2

File tree

6 files changed

+54
-3
lines changed

6 files changed

+54
-3
lines changed

benchmark/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# fast-xml-parser benchmarks
2+
3+
Part of [fast-xml-parser](../README.md)
4+
5+
## Building
6+
7+
```shell
8+
$ npm i
9+
```
10+
11+
## Testing
12+
13+
### All Benchmarks
14+
15+
```shell
16+
$ npm t
17+
```
18+
19+
### Parser Benchmars
20+
21+
```shell
22+
$ npm run parser
23+
```
24+
25+
### Builder Benchmarks
26+
27+
```shell
28+
$ npm run builder
29+
```
30+
31+
## License
32+
33+
See [../README.md](../README.md#license)

benchmark/XmlBuilder.js renamed to benchmark/XmlBuilder.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ const suite = new Benchmark.Suite("XML Builder benchmark");
66
import {XMLBuilder} from "../src/fxp.js";
77
import xml2js from "xml2js";
88
const xml2jsBuilder = new xml2js.Builder();
9+
import { dirname } from 'node:path';
10+
import { fileURLToPath } from 'node:url';
11+
12+
// compatibility
13+
const __dirname = dirname(fileURLToPath(import.meta.url));
914

1015
import fs from "fs";
1116
import path from "path";

benchmark/XmlParser.js renamed to benchmark/XmlParser.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import {XMLParser} from "../src/fxp.js";
55
import xml2js from "xml2js";
66
import fxpv3 from "fast-xml-parser";
77
import { convert } from 'xmlbuilder2';
8+
import { dirname } from 'node:path';
9+
import { fileURLToPath } from 'node:url';
10+
11+
// compatibility
12+
const __dirname = dirname(fileURLToPath(import.meta.url));
813

914
const suite = new Benchmark.Suite("XML Parser benchmark");
1015

benchmark/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"private": true,
55
"description": "Performance test",
66
"scripts": {
7-
"perf": "node perfTest3.js"
7+
"parser": "node XmlParser.mjs",
8+
"builder": "node XmlBuilder.mjs",
9+
"test": "npm run parser && npm run builder && node try.mjs"
810
},
911
"devDependencies": {
1012
"benchmark": "^2.1.4",

benchmark/try.js renamed to benchmark/try.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import fs from "fs";
22
import path from "path";
33
// const fileNamePath = path.join(__dirname, "../spec/assets/test.json");//1.5k
44
// const jsonData = JSON.parse(fs.readFileSync(fileNamePath).toString());
5+
import { dirname } from 'node:path';
6+
import { fileURLToPath } from 'node:url';
7+
8+
// compatibility
9+
const __dirname = dirname(fileURLToPath(import.meta.url));
510

611

712
// const xml2js = require("xml2js");
@@ -16,4 +21,4 @@ const xmlData = fs.readFileSync(fileNamePath).toString();
1621
const fxpParserForOrderedJs = new XMLParser({preserveOrder: true});
1722
console.log(
1823
JSON.stringify(fxpParserForOrderedJs.parse(xmlData), null, 4)
19-
);
24+
);

docs/CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Here is the check list to publish any change
1414
* Changes are well discussed by raising github issue. So they are well known by other contributors and users
1515
* Echoing the above point. The purpose / goal for the PR should be mentioned in the description.
1616
* Multiple unrelated changes should not be clubbed in single PR.
17-
* Please run perf tests `$ node benchmark\XmlParser.js` or `$ node benchmark\XmlBuilder.js` before and after the changes. And mention it in PR description.
17+
* Please run perf tests `$ node benchmark/XmlParser.mjs` or `$ node benchmark/XmlBuilder.mjs` before and after the changes. And mention it in PR description.
18+
* See [benchmark/README.md](../benchmark/README.md) for details
1819
* If you are adding any dependency (specially if it is not the dev dependency) please check that
1920
* it is not dependent on other language packages like c/c++
2021
* the package is not very old, very new, discontinued, or has any vulnerability etc.

0 commit comments

Comments
 (0)