-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSequentialStream.mjs
More file actions
68 lines (61 loc) · 2.46 KB
/
Copy pathSequentialStream.mjs
File metadata and controls
68 lines (61 loc) · 2.46 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import Benchmark from "benchmark";
import { Writable } from 'node:stream';
import { XMLParser as FlexParser } from "@nodable/flexible-xml-parser";
import { SequentialStreamBuilderFactory } from "@nodable/sequential-stream-builder";
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();
const nullSink = () => new Writable({ write(chunk, enc, cb) { cb(); } });
suite
.add("Fast XML Parser", function () {
const xmlData = fs.readFileSync(fileNamePath).toString();
const parser = new FastParser({
preserveOrder: true
})
const result = parser.parse(xmlData);
fs.writeFileSync('output_fxp.json', JSON.stringify(result));
})
.add("Flexible XML Parser", {
defer: true,
fn: function (deferred) {
const inStream = fs.createReadStream(fileNamePath);
const outStream = nullSink();
const parser = new FlexParser({
OutputBuilder: new SequentialStreamBuilderFactory({ stream: outStream })
});
parser.parseStream(inStream).then(() => {
outStream.end(() => deferred.resolve());
});
}
})
.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 });