diff --git a/README.md b/README.md index 967d6b9..657ebe6 100644 --- a/README.md +++ b/README.md @@ -93,60 +93,72 @@ Results by this library are marked with `*`. The source code of the benchmark is available at `benchmark/benchmark.ts`. ``` +Common + + Initialization / Load speed + + #1: html-entities x 2,986,166 ops/sec ±1.21% (85 runs sampled) + #2: entities x 2,211,849 ops/sec ±1.16% (82 runs sampled) + #3: he x 1,940,763 ops/sec ±1.07% (87 runs sampled) + HTML5 Encode test - * #1: html-entities.encode - html5, nonAscii x 362,978 ops/sec ±1.10% (93 runs sampled) - * #2: html-entities.encode - html5, nonAsciiPrintable x 343,554 ops/sec ±1.35% (93 runs sampled) - #3: entities.encodeHTML5 x 106,418 ops/sec ±0.41% (91 runs sampled) - #4: he.encode x 98,762 ops/sec ±0.93% (92 runs sampled) + #1: html-entities.encode - html5, nonAscii x 436,912 ops/sec ±0.37% (95 runs sampled) + #2: html-entities.encode - html5, nonAsciiPrintable x 420,014 ops/sec ±0.31% (97 runs sampled) + #3: entities.encodeNonAsciiHTML x 337,400 ops/sec ±0.38% (96 runs sampled) + #4: html-entities.encode - html5, extensive x 270,985 ops/sec ±0.52% (96 runs sampled) + #5: entities.encodeHTML x 128,155 ops/sec ±0.33% (91 runs sampled) + #6: he.encode x 115,127 ops/sec ±0.74% (93 runs sampled) Decode test - * #1: html-entities.decode - html5, strict x 291,466 ops/sec ±3.09% (86 runs sampled) - * #2: html-entities.decode - html5, body x 293,192 ops/sec ±5.33% (91 runs sampled) - * #3: html-entities.decode - html5, attribute x 272,764 ops/sec ±2.30% (91 runs sampled) - #4: entities.decodeHTML5 x 250,868 ops/sec ±0.59% (93 runs sampled) - #5: he.decode x 176,291 ops/sec ±4.48% (88 runs sampled) + #1: html-entities.decode - html5, strict x 345,565 ops/sec ±0.21% (95 runs sampled) + #2: entities.decodeHTMLStrict x 337,245 ops/sec ±0.59% (94 runs sampled) + #3: html-entities.decode - html5, body x 333,330 ops/sec ±0.75% (96 runs sampled) + #4: html-entities.decode - html5, attribute x 312,208 ops/sec ±0.31% (95 runs sampled) + #5: entities.decodeHTML x 275,014 ops/sec ±0.54% (95 runs sampled) + #6: he.decode x 182,385 ops/sec ±2.23% (89 runs sampled) HTML4 Encode test - * #1: html-entities.encode - html4, nonAscii x 364,044 ops/sec ±1.70% (92 runs sampled) - * #2: html-entities.encode - html4, nonAsciiPrintable x 328,646 ops/sec ±2.61% (88 runs sampled) - #3: entities.encodeHTML4 x 105,841 ops/sec ±0.53% (91 runs sampled) + #1: html-entities.encode - html4, nonAscii x 407,753 ops/sec ±0.24% (95 runs sampled) + #2: html-entities.encode - html4, nonAsciiPrintable x 393,630 ops/sec ±0.42% (96 runs sampled) + #3: html-entities.encode - html4, extensive x 202,439 ops/sec ±0.23% (95 runs sampled) Decode test - * #1: html-entities.decode - html4, body x 327,197 ops/sec ±0.76% (95 runs sampled) - * #2: html-entities.decode - html4, attribute x 317,243 ops/sec ±2.10% (90 runs sampled) - * #3: html-entities.decode - html4, strict x 312,160 ops/sec ±2.94% (83 runs sampled) - #4: entities.decodeHTML4 x 288,001 ops/sec ±0.85% (93 runs sampled) + #1: html-entities.decode - html4, strict x 373,579 ops/sec ±0.25% (95 runs sampled) + #2: html-entities.decode - html4, attribute x 365,673 ops/sec ±0.20% (96 runs sampled) + #3: html-entities.decode - html4, body x 364,291 ops/sec ±2.17% (95 runs sampled) XML Encode test - * #1: html-entities.encode - xml, nonAscii x 427,148 ops/sec ±1.40% (94 runs sampled) - * #2: html-entities.encode - xml, nonAsciiPrintable x 397,820 ops/sec ±2.77% (92 runs sampled) - #3: entities.encodeXML x 283,177 ops/sec ±3.57% (93 runs sampled) + #1: html-entities.encode - xml, nonAscii x 481,889 ops/sec ±0.43% (98 runs sampled) + #2: html-entities.encode - xml, nonAsciiPrintable x 459,323 ops/sec ±0.33% (95 runs sampled) + #3: entities.encodeXML x 352,201 ops/sec ±1.12% (93 runs sampled) + #4: html-entities.encode - xml, extensive x 266,395 ops/sec ±0.23% (97 runs sampled) Decode test - * #1: html-entities.decode - xml, strict x 407,364 ops/sec ±0.55% (91 runs sampled) - #2: entities.decodeXML x 405,984 ops/sec ±0.78% (94 runs sampled) - * #3: html-entities.decode - xml, body x 402,167 ops/sec ±0.67% (95 runs sampled) - * #4: html-entities.decode - xml, attribute x 387,630 ops/sec ±2.51% (94 runs sampled) - #5: entities.decodeXMLStrict x 390,023 ops/sec ±7.37% (86 runs sampled) + #1: html-entities.decode - xml, body x 434,407 ops/sec ±0.22% (94 runs sampled) + #2: html-entities.decode - xml, strict x 430,113 ops/sec ±0.26% (95 runs sampled) + #3: entities.decodeXML x 428,018 ops/sec ±0.54% (97 runs sampled) + #4: html-entities.decode - xml, attribute x 426,291 ops/sec ±0.39% (95 runs sampled) Escaping Escape test - #1: he.escape x 1,163,620 ops/sec ±2.53% (88 runs sampled) - * #2: html-entities.encode - xml, specialChars x 1,087,350 ops/sec ±4.06% (91 runs sampled) + #1: he.escape x 1,145,770 ops/sec ±0.24% (97 runs sampled) + #2: html-entities.encode - xml, specialChars x 1,100,040 ops/sec ±1.80% (92 runs sampled) + #3: entities.escapeUTF8 x 728,382 ops/sec ±0.56% (93 runs sampled) + #4: entities.escape x 313,666 ops/sec ±0.27% (97 runs sampled) ``` License diff --git a/benchmark/benchmark.ts b/benchmark/benchmark.ts index 68497a2..9ed848d 100644 --- a/benchmark/benchmark.ts +++ b/benchmark/benchmark.ts @@ -31,12 +31,15 @@ function createRequireTests(modules: Record) { function createHtml5EncodeMethods(textToEncode: string) { const heOptions = {useNamedReferences: true}; const nonAsciiPrintable: EncodeOptions = {level: 'html5', mode: 'nonAsciiPrintable'}; + const extensive: EncodeOptions = {level: 'html5', mode: 'extensive'}; const nonAscii: EncodeOptions = {level: 'html5', mode: 'nonAscii'}; return { 'html-entities.encode - html5, nonAscii': () => encode(textToEncode, nonAscii), 'html-entities.encode - html5, nonAsciiPrintable': () => encode(textToEncode, nonAsciiPrintable), + 'html-entities.encode - html5, extensive': () => encode(textToEncode, extensive), '(old) Html5Entities.encodeNonASCII': () => html5Entities.encodeNonASCII(textToEncode), - 'entities.encodeHTML5': () => entities.encodeHTML5(textToEncode), + 'entities.encodeHTML': () => entities.encodeHTML(textToEncode), + 'entities.encodeNonAsciiHTML': () => entities.encodeNonAsciiHTML(textToEncode), 'he.encode': () => he.encode(textToEncode, heOptions) }; } @@ -50,19 +53,21 @@ function createHtml5DecodeMethods(textToDecode: string) { 'html-entities.decode - html5, body': () => decode(textToDecode, body), 'html-entities.decode - html5, attribute': () => decode(textToDecode, attribute), '(old) Html5Entities.decode': () => html5Entities.decode(textToDecode), - 'entities.decodeHTML5': () => entities.decodeHTML5(textToDecode), + 'entities.decodeHTML': () => entities.decodeHTML(textToDecode), + 'entities.decodeHTMLStrict': () => entities.decodeHTMLStrict(textToDecode), 'he.decode': () => he.decode(textToDecode) }; } function createHtml4EncodeMethods(textToEncode: string) { const nonAsciiPrintable: EncodeOptions = {level: 'html4', mode: 'nonAsciiPrintable'}; + const extensive: EncodeOptions = {level: 'html4', mode: 'extensive'}; const nonAscii: EncodeOptions = {level: 'html4', mode: 'nonAscii'}; return { 'html-entities.encode - html4, nonAscii': () => encode(textToEncode, nonAscii), 'html-entities.encode - html4, nonAsciiPrintable': () => encode(textToEncode, nonAsciiPrintable), - '(old) Html4Entities.encodeNonASCII': () => html4Entities.encodeNonASCII(textToEncode), - 'entities.encodeHTML4': () => entities.encodeHTML4(textToEncode) + 'html-entities.encode - html4, extensive': () => encode(textToEncode, extensive), + '(old) Html4Entities.encodeNonASCII': () => html4Entities.encodeNonASCII(textToEncode) }; } @@ -74,17 +79,18 @@ function createHtml4DecodeMethods(textToDecode: string) { 'html-entities.decode - html4, strict': () => decode(textToDecode, strict), 'html-entities.decode - html4, body': () => decode(textToDecode, body), 'html-entities.decode - html4, attribute': () => decode(textToDecode, attribute), - '(old) Html4Entities.decode': () => html4Entities.decode(textToDecode), - 'entities.decodeHTML4': () => entities.decodeHTML4(textToDecode) + '(old) Html4Entities.decode': () => html4Entities.decode(textToDecode) }; } function createXmlEncodeMethods(textToEncode: string) { const nonAsciiPrintable: EncodeOptions = {level: 'xml', mode: 'nonAsciiPrintable'}; + const extensive: EncodeOptions = {level: 'xml', mode: 'extensive'}; const nonAscii: EncodeOptions = {level: 'xml', mode: 'nonAscii'}; return { 'html-entities.encode - xml, nonAscii': () => encode(textToEncode, nonAscii), 'html-entities.encode - xml, nonAsciiPrintable': () => encode(textToEncode, nonAsciiPrintable), + 'html-entities.encode - xml, extensive': () => encode(textToEncode, extensive), '(old) XmlEntities.encodeNonASCII': () => xmlEntities.encode(textToEncode), 'entities.encodeXML': () => entities.encodeXML(textToEncode) }; @@ -99,8 +105,7 @@ function createXmlDecodeMethods(textToDecode: string) { 'html-entities.decode - xml, body': () => decode(textToDecode, body), 'html-entities.decode - xml, attribute': () => decode(textToDecode, attribute), '(old) XmlEntities.decode': () => xmlEntities.decode(textToDecode), - 'entities.decodeXML': () => entities.decodeXML(textToDecode), - 'entities.decodeXMLStrict': () => entities.decodeXMLStrict(textToDecode) + 'entities.decodeXML': () => entities.decodeXML(textToDecode) }; } @@ -109,7 +114,9 @@ function createEscapeMethods(textToEncode: string) { return { 'html-entities.encode - xml, specialChars': () => encode(textToEncode, specialChars), '(old) XmlEntities.encode': () => xmlEntities.encode(textToEncode), - 'he.escape': () => he.escape(textToEncode) + 'he.escape': () => he.escape(textToEncode), + 'entities.escapeUTF8': () => entities.escapeUTF8(textToEncode), + 'entities.escape': () => entities.escape(textToEncode) }; }