-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompactOutput.mjs
More file actions
53 lines (45 loc) · 1.72 KB
/
CompactOutput.mjs
File metadata and controls
53 lines (45 loc) · 1.72 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
import Benchmark from "benchmark";
import { XMLParser as FlexParser } from "@nodable/flexible-xml-parser";
import { XMLParser as FastParser } from "fast-xml-parser";
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");
import fs from "fs";
import path from "path";
const fileNamePath = path.join(__dirname, "./assets/ptest.xml");//with CDATA
// const fileNamePath = path.join(__dirname, "./assets/ptest_with_prolog.xml");//with CDATA
// const fileNamePath = path.join(__dirname, "./assets/sample.xml");//1.5k
// const fileNamePath = path.join(__dirname, "./assets/midsize.xml");//13m
// const fileNamePath = path.join(__dirname, "./assets/large.xml");//98m
const xmlData = fs.readFileSync(fileNamePath).toString();
suite
.add("Fast XML Parser", function () {
const parser = new FastParser({})
parser.parse(xmlData);
})
.add("Flexible XML Parser", function () {
const parser = new FlexParser({})
parser.parse(xmlData);
})
.on("start", function () {
console.log("Running Suite: " + this.name);
})
.on("error", function (e) {
console.log("Error in Suite: " + this.name, e);
})
.on("abort", function (e) {
console.log("Aborting Suite: " + this.name, e);
})
/*.on('cycle',function(event){
console.log("Suite ID:" + event.target.id);
})*/
// add listeners
.on("complete", function () {
for (let j = 0; j < this.length; j++) {
console.log(this[j].name + " : " + this[j].hz + " requests/second");
}
})
// run async
.run({ "async": true });