diff --git a/benchmark/README.md b/benchmark/README.md new file mode 100644 index 00000000..7f6b05ca --- /dev/null +++ b/benchmark/README.md @@ -0,0 +1,33 @@ +# fast-xml-parser benchmarks + +Part of [fast-xml-parser](../README.md) + +## Building + +```shell +$ npm i +``` + +## Testing + +### All Benchmarks + +```shell +$ npm t +``` + +### Parser Benchmars + +```shell +$ npm run parser +``` + +### Builder Benchmarks + +```shell +$ npm run builder +``` + +## License + +See [../README.md](../README.md#license) diff --git a/benchmark/XmlBuilder.js b/benchmark/XmlBuilder.mjs similarity index 90% rename from benchmark/XmlBuilder.js rename to benchmark/XmlBuilder.mjs index ab22e10e..e82e08a0 100644 --- a/benchmark/XmlBuilder.js +++ b/benchmark/XmlBuilder.mjs @@ -6,6 +6,11 @@ const suite = new Benchmark.Suite("XML Builder benchmark"); import {XMLBuilder} from "../src/fxp.js"; import xml2js from "xml2js"; const xml2jsBuilder = new xml2js.Builder(); +import { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +// compatibility +const __dirname = dirname(fileURLToPath(import.meta.url)); import fs from "fs"; import path from "path"; diff --git a/benchmark/XmlParser.js b/benchmark/XmlParser.mjs similarity index 94% rename from benchmark/XmlParser.js rename to benchmark/XmlParser.mjs index 21c8b18f..4ed222db 100644 --- a/benchmark/XmlParser.js +++ b/benchmark/XmlParser.mjs @@ -5,6 +5,11 @@ import {XMLParser} from "../src/fxp.js"; import xml2js from "xml2js"; import fxpv3 from "fast-xml-parser"; import { convert } from 'xmlbuilder2'; +import { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +// compatibility +const __dirname = dirname(fileURLToPath(import.meta.url)); const suite = new Benchmark.Suite("XML Parser benchmark"); diff --git a/benchmark/package.json b/benchmark/package.json index a6cca0f1..204dae6d 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -4,7 +4,9 @@ "private": true, "description": "Performance test", "scripts": { - "perf": "node perfTest3.js" + "parser": "node XmlParser.mjs", + "builder": "node XmlBuilder.mjs", + "test": "npm run parser && npm run builder && node try.mjs" }, "devDependencies": { "benchmark": "^2.1.4", diff --git a/benchmark/try.js b/benchmark/try.mjs similarity index 80% rename from benchmark/try.js rename to benchmark/try.mjs index 87858a18..e77a6b30 100644 --- a/benchmark/try.js +++ b/benchmark/try.mjs @@ -2,6 +2,11 @@ import fs from "fs"; import path from "path"; // const fileNamePath = path.join(__dirname, "../spec/assets/test.json");//1.5k // const jsonData = JSON.parse(fs.readFileSync(fileNamePath).toString()); +import { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +// compatibility +const __dirname = dirname(fileURLToPath(import.meta.url)); // const xml2js = require("xml2js"); @@ -16,4 +21,4 @@ const xmlData = fs.readFileSync(fileNamePath).toString(); const fxpParserForOrderedJs = new XMLParser({preserveOrder: true}); console.log( JSON.stringify(fxpParserForOrderedJs.parse(xmlData), null, 4) -); \ No newline at end of file +); diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 544f0583..fcd4fda5 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -14,7 +14,8 @@ Here is the check list to publish any change * Changes are well discussed by raising github issue. So they are well known by other contributors and users * Echoing the above point. The purpose / goal for the PR should be mentioned in the description. * Multiple unrelated changes should not be clubbed in single PR. -* Please run perf tests `$ node benchmark\XmlParser.js` or `$ node benchmark\XmlBuilder.js` before and after the changes. And mention it in PR description. +* Please run perf tests `$ node benchmark/XmlParser.mjs` or `$ node benchmark/XmlBuilder.mjs` before and after the changes. And mention it in PR description. + * See [benchmark/README.md](../benchmark/README.md) for details * If you are adding any dependency (specially if it is not the dev dependency) please check that * it is not dependent on other language packages like c/c++ * the package is not very old, very new, discontinued, or has any vulnerability etc.