Created
June 24, 2023 11:29
-
-
Save rojvv/f9988cc4798374f177214a4c3df6e8ee to your computer and use it in GitHub Desktop.
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
// Install Deno: https://deno.land. | |
// Run with the command | |
// deno bench | |
const array1 = crypto.getRandomValues(new Uint8Array([1024 * 1024])); | |
const array2 = crypto.getRandomValues(new Uint8Array([1024 * 1024])); | |
const array3 = crypto.getRandomValues(new Uint8Array([1024 * 1024])); | |
const array4 = crypto.getRandomValues(new Uint8Array([1024 * 1024])); | |
const array5 = crypto.getRandomValues(new Uint8Array([1024 * 1024])); | |
Deno.bench("spread syntax", () => { | |
const _ = new Uint8Array([ | |
...array1, | |
...array2, | |
...array3, | |
...array4, | |
...array5, | |
]); | |
}); | |
Deno.bench("push()", () => { | |
const __ = []; | |
for (const item of array1) { | |
__.push(item); | |
} | |
for (const item of array2) { | |
__.push(item); | |
} | |
for (const item of array3) { | |
__.push(item); | |
} | |
for (const item of array4) { | |
__.push(item); | |
} | |
for (const item of array5) { | |
__.push(item); | |
} | |
const _ = new Uint8Array(__); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment