hex pairs to array buffer

Benchmark created on


Description

convert hex pairs into array buffer

Setup

let hexString = "a0ad5928297d11874898c3a7df32839fc65b6f5abf8105cc126ccc158ddcba82ec713a93c3de97";

function hexToAb2(hexString) {
    return new Uint8Array(hexString.match(/[\da-f]{2}/gi).map((h) => parseInt(h, 16)))
}

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;
}

Test runner

Ready to run.

Testing in
TestOps/sec
match + map
hexToAb2(hexString);
ready
plain loop
hexPairsToAb(hexString);
ready

Revisions

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