It appears that copying a Uint8Array
into a Uint8ClampedArray
is much slower than cloning the Uint8Array
and using its underlying ArrayBuffer
:
const foo = new Uint8Array(0x10000000); // 256MiB
console.time('Copy into Uint8ClampedArray');
const bar = new Uint8ClampedArray(foo);
console.timeEnd('Copy into Uint8ClampedArray');
The code above clocks at ~550ms on my machine.
const foo = new Uint8Array(0x10000000); // 256MiB
console.time('Clone, then use ArrayBuffer');
const bar = new Uint8ClampedArray(new Uint8Array(foo).buffer);
console.timeEnd('Clone, then use ArrayBuffer');
The code above clocks at ~30ms on my machine.