Skip to content

Instantly share code, notes, and snippets.

@roj1512
Created June 24, 2023 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roj1512/f9988cc4798374f177214a4c3df6e8ee to your computer and use it in GitHub Desktop.
Save roj1512/f9988cc4798374f177214a4c3df6e8ee to your computer and use it in GitHub Desktop.
// 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