-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (52 loc) · 1.69 KB
/
index.js
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
'use strict';
const fs = require('fs');
const os = require('os');
const { parseXml } = require('@rgrove/parse-xml');
const { version: parseXmlVersion } = require('@rgrove/parse-xml/package.json');
const benny = require('benny');
const { XMLParser: FastXmlParser } = require('fast-xml-parser');
const { version: fastXmlParserVersion } = require('fast-xml-parser/package.json');
const libxmljs2 = require('libxmljs2');
const { version: libxmljs2Version } = require('libxmljs2/package.json');
const xmldoc = require('xmldoc');
const { version: xmldocVersion } = require('xmldoc/package.json');
const suites = [
{
name: 'Small document',
filename: `${__dirname}/fixtures/small.xml`,
},
{
name: 'Medium document',
filename: `${__dirname}/fixtures/medium.xml`,
},
{
name: 'Large document',
filename: `${__dirname}/fixtures/large.xml`,
},
];
console.log(`Node.js ${process.version} / ${os.type()} ${os.arch()}\n${os.cpus()[0].model}\n`);
for (let { filename, name } of suites) {
let fastXmlParserOptions = {
ignoreAttributes: false,
processEntities: false,
};
let xml = fs.readFileSync(filename, 'utf8');
benny.suite(
`${name} (${xml.length} bytes)`,
benny.add(`@rgrove/parse-xml ${parseXmlVersion}`, () => {
parseXml(xml);
}),
benny.add(`fast-xml-parser ${fastXmlParserVersion}`, () => {
new FastXmlParser(fastXmlParserOptions).parse(xml);
}),
benny.add(`libxmljs2 ${libxmljs2Version} (native)`, () => {
libxmljs2.parseXmlString(xml);
}),
benny.add(`xmldoc ${xmldocVersion} (sax-js)`, () => {
new xmldoc.XmlDocument(xml);
}),
benny.cycle(),
benny.complete(),
benny.complete(() => console.log()),
);
}