Spread and map vs Array.from

Benchmark created on


Setup

const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);

Teardown

bytes = undefined;

Test runner

Ready to run.

Testing in
TestOps/sec
Spread
[...bytes]
        .map((b, i) =>
            [4, 6, 8, 10].includes(i) ? `-${b.toString(16).padStart(2, "0")}` : b.toString(16).padStart(2, "0")
        )
        .join("");
ready
Array.from
Array.from(bytes, (b, i) =>
        [4, 6, 8, 10].includes(i) ? `-${b.toString(16).padStart(2, "0")}` : b.toString(16).padStart(2, "0")
    )
    .join("");
ready

Revisions

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