src: improve hex encoding performance
Checklist
-
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines
Affected core subsystem(s)
- buffer
Description of change
This commit improves hex encoding performance by converting more than one byte at a time and by avoiding the use of a lookup table.
Encoding benchmark results:
buffers/buffer-hex.js n=10000000 mode="enc" len=1024 181.03 % *** 1.144588e-22
buffers/buffer-hex.js n=10000000 mode="enc" len=64 31.83 % *** 2.142052e-05
For fun I tested it on arm64 too, although I had to lower n
to get it to finish in a reasonable amount of time:
buffers/buffer-hex.js n=100000 mode="enc" len=1024 85.52 % *** 4.753473e-33
buffers/buffer-hex.js n=100000 mode="enc" len=64 10.60 % *** 1.176254e-15
CI: https://ci.nodejs.org/job/node-test-pull-request/5414/
CI: https://ci.nodejs.org/job/node-test-pull-request/5431/
CI: https://ci.nodejs.org/job/node-test-pull-request/5436/