array buffer to hex pairs (v3)

Revision 3 of this benchmark created on


Preparation HTML

<script src="https://unpkg.com/core-js-bundle@3.40.0/minified.js"></script>

Setup

let hexString = "a0ad5928297d11874898c3a7df32839fc65b6f5abf8105cc126ccc158ddcba82ec713a93c3de97";

function hexPairsToAb(string) {
    let arrayBuffer = new Uint8Array(Math.ceil(string.length / 2));
    for (let i = 0; i < string.length; i += 2) {
        arrayBuffer[i / 2] = parseInt(string.slice(i, i + 2), 16);
    }
    return arrayBuffer;
}

let aBuff = hexPairsToAb(hexString);

function abToHex(bytes) {
    return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
}

Test runner

Ready to run.

Testing in
TestOps/sec
Array.from map join
abToHex(aBuff);
ready
.toHex polyfill
aBuff.toHex();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.