Repository navigation
Expand file tree
/
Copy pathtransform.js
More file actions
71 lines (61 loc) · 1.51 KB
/
Copy pathtransform.js
File metadata and controls
71 lines (61 loc) · 1.51 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
69
70
71
'use strict';
const fs = require('fs');
const { transform, destroy } = require('..');
const { XMLParser } = require('fast-xml-parser');
const xml2js = require('xml2js');
const xmljs = require('xml-js');
const txml = require('txml');
const fastXmlParser = new XMLParser();
const xml2jsParser = new xml2js.Parser();
const xml = fs.readFileSync(__dirname + '/./fixtures/60kb.xml', 'utf-8');
const template = {
cache_key: '/HotelListResponse/cacheKey',
hotels: [
'//HotelSummary',
{
hotel_id: 'hotelId',
name: 'name',
rooms: [
'RoomRateDetailsList/RoomRateDetails',
{
rates: [
'RateInfos/RateInfo',
{
currency: 'ChargeableRateInfo/@currencyCode',
non_refundable: 'boolean(nonRefundable = "true")',
price: 'number(ChargeableRateInfo/@total)',
},
],
room_name: 'roomDescription',
room_type_id: 'roomTypeCode',
},
],
},
],
session_id: '/HotelListResponse/customerSessionId',
};
(async () => {
const { run, bench, summary } = await import('mitata');
summary(() => {
bench('camaro v6', function* () {
yield async () => await transform(xml, template);
});
bench('txml', () => {
txml.parse(xml);
});
bench('fast-xml-parser', () => {
fastXmlParser.parse(xml);
});
bench('xml2js', function* () {
yield async () => await xml2jsParser.parseStringPromise(xml);
});
bench('xml-js', () => {
xmljs.xml2js(xml);
});
});
await run();
await destroy();
})().catch((err) => {
console.error(err);
process.exitCode = 1;
});