forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: improve normalize encoding performance
This focuses on the common case by making sure they are prioritized. It also changes some typeof checks to test for undefined since that is faster and it adds a benchmark. PR-URL: nodejs#18790 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
4 changed files
with
101 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
encoding: [ | ||
'ascii', | ||
'ASCII', | ||
'base64', | ||
'BASE64', | ||
'binary', | ||
'BINARY', | ||
'hex', | ||
'HEX', | ||
'latin1', | ||
'LATIN1', | ||
'ucs-2', | ||
'UCS-2', | ||
'ucs2', | ||
'UCS2', | ||
'utf-16le', | ||
'UTF-16LE', | ||
'utf-8', | ||
'UTF-8', | ||
'utf16le', | ||
'UTF16LE', | ||
'utf8', | ||
'UTF8' | ||
], | ||
n: [1e6] | ||
}, { | ||
flags: ['--expose-internals'] | ||
}); | ||
|
||
function main({ encoding, n }) { | ||
const { normalizeEncoding } = require('internal/util'); | ||
|
||
bench.start(); | ||
for (var i = 0; i < n; i++) { | ||
normalizeEncoding(encoding); | ||
} | ||
bench.end(n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters