Skip to content

Commit e9ffb24

Browse files
committed
Update benchmark, use appropriate methods from entities, fixes #51
1 parent 3e4104a commit e9ffb24

File tree

2 files changed

+54
-35
lines changed

2 files changed

+54
-35
lines changed

README.md

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,60 +93,72 @@ Results by this library are marked with `*`.
9393
The source code of the benchmark is available at `benchmark/benchmark.ts`.
9494

9595
```
96+
Common
97+
98+
Initialization / Load speed
99+
100+
#1: html-entities x 2,986,166 ops/sec ±1.21% (85 runs sampled)
101+
#2: entities x 2,211,849 ops/sec ±1.16% (82 runs sampled)
102+
#3: he x 1,940,763 ops/sec ±1.07% (87 runs sampled)
103+
96104
HTML5
97105
98106
Encode test
99107
100-
* #1: html-entities.encode - html5, nonAscii x 362,978 ops/sec ±1.10% (93 runs sampled)
101-
* #2: html-entities.encode - html5, nonAsciiPrintable x 343,554 ops/sec ±1.35% (93 runs sampled)
102-
#3: entities.encodeHTML5 x 106,418 ops/sec ±0.41% (91 runs sampled)
103-
#4: he.encode x 98,762 ops/sec ±0.93% (92 runs sampled)
108+
#1: html-entities.encode - html5, nonAscii x 436,912 ops/sec ±0.37% (95 runs sampled)
109+
#2: html-entities.encode - html5, nonAsciiPrintable x 420,014 ops/sec ±0.31% (97 runs sampled)
110+
#3: entities.encodeNonAsciiHTML x 337,400 ops/sec ±0.38% (96 runs sampled)
111+
#4: html-entities.encode - html5, extensive x 270,985 ops/sec ±0.52% (96 runs sampled)
112+
#5: entities.encodeHTML x 128,155 ops/sec ±0.33% (91 runs sampled)
113+
#6: he.encode x 115,127 ops/sec ±0.74% (93 runs sampled)
104114
105115
Decode test
106116
107-
* #1: html-entities.decode - html5, strict x 291,466 ops/sec ±3.09% (86 runs sampled)
108-
* #2: html-entities.decode - html5, body x 293,192 ops/sec ±5.33% (91 runs sampled)
109-
* #3: html-entities.decode - html5, attribute x 272,764 ops/sec ±2.30% (91 runs sampled)
110-
#4: entities.decodeHTML5 x 250,868 ops/sec ±0.59% (93 runs sampled)
111-
#5: he.decode x 176,291 ops/sec ±4.48% (88 runs sampled)
117+
#1: html-entities.decode - html5, strict x 345,565 ops/sec ±0.21% (95 runs sampled)
118+
#2: entities.decodeHTMLStrict x 337,245 ops/sec ±0.59% (94 runs sampled)
119+
#3: html-entities.decode - html5, body x 333,330 ops/sec ±0.75% (96 runs sampled)
120+
#4: html-entities.decode - html5, attribute x 312,208 ops/sec ±0.31% (95 runs sampled)
121+
#5: entities.decodeHTML x 275,014 ops/sec ±0.54% (95 runs sampled)
122+
#6: he.decode x 182,385 ops/sec ±2.23% (89 runs sampled)
112123
113124
HTML4
114125
115126
Encode test
116127
117-
* #1: html-entities.encode - html4, nonAscii x 364,044 ops/sec ±1.70% (92 runs sampled)
118-
* #2: html-entities.encode - html4, nonAsciiPrintable x 328,646 ops/sec ±2.61% (88 runs sampled)
119-
#3: entities.encodeHTML4 x 105,841 ops/sec ±0.53% (91 runs sampled)
128+
#1: html-entities.encode - html4, nonAscii x 407,753 ops/sec ±0.24% (95 runs sampled)
129+
#2: html-entities.encode - html4, nonAsciiPrintable x 393,630 ops/sec ±0.42% (96 runs sampled)
130+
#3: html-entities.encode - html4, extensive x 202,439 ops/sec ±0.23% (95 runs sampled)
120131
121132
Decode test
122133
123-
* #1: html-entities.decode - html4, body x 327,197 ops/sec ±0.76% (95 runs sampled)
124-
* #2: html-entities.decode - html4, attribute x 317,243 ops/sec ±2.10% (90 runs sampled)
125-
* #3: html-entities.decode - html4, strict x 312,160 ops/sec ±2.94% (83 runs sampled)
126-
#4: entities.decodeHTML4 x 288,001 ops/sec ±0.85% (93 runs sampled)
134+
#1: html-entities.decode - html4, strict x 373,579 ops/sec ±0.25% (95 runs sampled)
135+
#2: html-entities.decode - html4, attribute x 365,673 ops/sec ±0.20% (96 runs sampled)
136+
#3: html-entities.decode - html4, body x 364,291 ops/sec ±2.17% (95 runs sampled)
127137
128138
XML
129139
130140
Encode test
131141
132-
* #1: html-entities.encode - xml, nonAscii x 427,148 ops/sec ±1.40% (94 runs sampled)
133-
* #2: html-entities.encode - xml, nonAsciiPrintable x 397,820 ops/sec ±2.77% (92 runs sampled)
134-
#3: entities.encodeXML x 283,177 ops/sec ±3.57% (93 runs sampled)
142+
#1: html-entities.encode - xml, nonAscii x 481,889 ops/sec ±0.43% (98 runs sampled)
143+
#2: html-entities.encode - xml, nonAsciiPrintable x 459,323 ops/sec ±0.33% (95 runs sampled)
144+
#3: entities.encodeXML x 352,201 ops/sec ±1.12% (93 runs sampled)
145+
#4: html-entities.encode - xml, extensive x 266,395 ops/sec ±0.23% (97 runs sampled)
135146
136147
Decode test
137148
138-
* #1: html-entities.decode - xml, strict x 407,364 ops/sec ±0.55% (91 runs sampled)
139-
#2: entities.decodeXML x 405,984 ops/sec ±0.78% (94 runs sampled)
140-
* #3: html-entities.decode - xml, body x 402,167 ops/sec ±0.67% (95 runs sampled)
141-
* #4: html-entities.decode - xml, attribute x 387,630 ops/sec ±2.51% (94 runs sampled)
142-
#5: entities.decodeXMLStrict x 390,023 ops/sec ±7.37% (86 runs sampled)
149+
#1: html-entities.decode - xml, body x 434,407 ops/sec ±0.22% (94 runs sampled)
150+
#2: html-entities.decode - xml, strict x 430,113 ops/sec ±0.26% (95 runs sampled)
151+
#3: entities.decodeXML x 428,018 ops/sec ±0.54% (97 runs sampled)
152+
#4: html-entities.decode - xml, attribute x 426,291 ops/sec ±0.39% (95 runs sampled)
143153
144154
Escaping
145155
146156
Escape test
147157
148-
#1: he.escape x 1,163,620 ops/sec ±2.53% (88 runs sampled)
149-
* #2: html-entities.encode - xml, specialChars x 1,087,350 ops/sec ±4.06% (91 runs sampled)
158+
#1: he.escape x 1,145,770 ops/sec ±0.24% (97 runs sampled)
159+
#2: html-entities.encode - xml, specialChars x 1,100,040 ops/sec ±1.80% (92 runs sampled)
160+
#3: entities.escapeUTF8 x 728,382 ops/sec ±0.56% (93 runs sampled)
161+
#4: entities.escape x 313,666 ops/sec ±0.27% (97 runs sampled)
150162
```
151163

152164
License

benchmark/benchmark.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ function createRequireTests(modules: Record<string, string>) {
3131
function createHtml5EncodeMethods(textToEncode: string) {
3232
const heOptions = {useNamedReferences: true};
3333
const nonAsciiPrintable: EncodeOptions = {level: 'html5', mode: 'nonAsciiPrintable'};
34+
const extensive: EncodeOptions = {level: 'html5', mode: 'extensive'};
3435
const nonAscii: EncodeOptions = {level: 'html5', mode: 'nonAscii'};
3536
return {
3637
'html-entities.encode - html5, nonAscii': () => encode(textToEncode, nonAscii),
3738
'html-entities.encode - html5, nonAsciiPrintable': () => encode(textToEncode, nonAsciiPrintable),
39+
'html-entities.encode - html5, extensive': () => encode(textToEncode, extensive),
3840
'(old) Html5Entities.encodeNonASCII': () => html5Entities.encodeNonASCII(textToEncode),
39-
'entities.encodeHTML5': () => entities.encodeHTML5(textToEncode),
41+
'entities.encodeHTML': () => entities.encodeHTML(textToEncode),
42+
'entities.encodeNonAsciiHTML': () => entities.encodeNonAsciiHTML(textToEncode),
4043
'he.encode': () => he.encode(textToEncode, heOptions)
4144
};
4245
}
@@ -50,19 +53,21 @@ function createHtml5DecodeMethods(textToDecode: string) {
5053
'html-entities.decode - html5, body': () => decode(textToDecode, body),
5154
'html-entities.decode - html5, attribute': () => decode(textToDecode, attribute),
5255
'(old) Html5Entities.decode': () => html5Entities.decode(textToDecode),
53-
'entities.decodeHTML5': () => entities.decodeHTML5(textToDecode),
56+
'entities.decodeHTML': () => entities.decodeHTML(textToDecode),
57+
'entities.decodeHTMLStrict': () => entities.decodeHTMLStrict(textToDecode),
5458
'he.decode': () => he.decode(textToDecode)
5559
};
5660
}
5761

5862
function createHtml4EncodeMethods(textToEncode: string) {
5963
const nonAsciiPrintable: EncodeOptions = {level: 'html4', mode: 'nonAsciiPrintable'};
64+
const extensive: EncodeOptions = {level: 'html4', mode: 'extensive'};
6065
const nonAscii: EncodeOptions = {level: 'html4', mode: 'nonAscii'};
6166
return {
6267
'html-entities.encode - html4, nonAscii': () => encode(textToEncode, nonAscii),
6368
'html-entities.encode - html4, nonAsciiPrintable': () => encode(textToEncode, nonAsciiPrintable),
64-
'(old) Html4Entities.encodeNonASCII': () => html4Entities.encodeNonASCII(textToEncode),
65-
'entities.encodeHTML4': () => entities.encodeHTML4(textToEncode)
69+
'html-entities.encode - html4, extensive': () => encode(textToEncode, extensive),
70+
'(old) Html4Entities.encodeNonASCII': () => html4Entities.encodeNonASCII(textToEncode)
6671
};
6772
}
6873

@@ -74,17 +79,18 @@ function createHtml4DecodeMethods(textToDecode: string) {
7479
'html-entities.decode - html4, strict': () => decode(textToDecode, strict),
7580
'html-entities.decode - html4, body': () => decode(textToDecode, body),
7681
'html-entities.decode - html4, attribute': () => decode(textToDecode, attribute),
77-
'(old) Html4Entities.decode': () => html4Entities.decode(textToDecode),
78-
'entities.decodeHTML4': () => entities.decodeHTML4(textToDecode)
82+
'(old) Html4Entities.decode': () => html4Entities.decode(textToDecode)
7983
};
8084
}
8185

8286
function createXmlEncodeMethods(textToEncode: string) {
8387
const nonAsciiPrintable: EncodeOptions = {level: 'xml', mode: 'nonAsciiPrintable'};
88+
const extensive: EncodeOptions = {level: 'xml', mode: 'extensive'};
8489
const nonAscii: EncodeOptions = {level: 'xml', mode: 'nonAscii'};
8590
return {
8691
'html-entities.encode - xml, nonAscii': () => encode(textToEncode, nonAscii),
8792
'html-entities.encode - xml, nonAsciiPrintable': () => encode(textToEncode, nonAsciiPrintable),
93+
'html-entities.encode - xml, extensive': () => encode(textToEncode, extensive),
8894
'(old) XmlEntities.encodeNonASCII': () => xmlEntities.encode(textToEncode),
8995
'entities.encodeXML': () => entities.encodeXML(textToEncode)
9096
};
@@ -99,8 +105,7 @@ function createXmlDecodeMethods(textToDecode: string) {
99105
'html-entities.decode - xml, body': () => decode(textToDecode, body),
100106
'html-entities.decode - xml, attribute': () => decode(textToDecode, attribute),
101107
'(old) XmlEntities.decode': () => xmlEntities.decode(textToDecode),
102-
'entities.decodeXML': () => entities.decodeXML(textToDecode),
103-
'entities.decodeXMLStrict': () => entities.decodeXMLStrict(textToDecode)
108+
'entities.decodeXML': () => entities.decodeXML(textToDecode)
104109
};
105110
}
106111

@@ -109,7 +114,9 @@ function createEscapeMethods(textToEncode: string) {
109114
return {
110115
'html-entities.encode - xml, specialChars': () => encode(textToEncode, specialChars),
111116
'(old) XmlEntities.encode': () => xmlEntities.encode(textToEncode),
112-
'he.escape': () => he.escape(textToEncode)
117+
'he.escape': () => he.escape(textToEncode),
118+
'entities.escapeUTF8': () => entities.escapeUTF8(textToEncode),
119+
'entities.escape': () => entities.escape(textToEncode)
113120
};
114121
}
115122

0 commit comments

Comments
 (0)