Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
Why is copying a Uint8Array to a Uint8ClampedArray slower than copying a Uint8Array to a new Uint8Array?

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 ~160ms on my machine (Chrome v96, MacBook Pro).

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 ~70ms on my machine.

Firefox gives similar stats (140ms vs 60ms), while Safari shows more extreme differences (550ms vs 30ms).

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm not seeing those time differences in browser or in NodeJs

foo = new Uint8Array(256 * 1024**2); // 256MiB
console.time(label = 'Copy into Uint8ClampedArray');
bar = new Uint8ClampedArray(foo);
console.timeEnd(label);

foo = new Uint8Array(256 * 1024**2); // 256MiB
console.time(label = 'Clone, then use ArrayBuffer');
bar = new Uint8ClampedArray(new Uint8Array(foo).buffer);
console.timeEnd(label);
$ node -v && node test.js
v17.2.0
Copy into Uint8ClampedArray: 174.049ms
Clone, then use ArrayBuffer: 193.819ms

$ node -v && node test.js
v17.2.0
Copy into Uint8ClampedArray: 170.152ms
Clone, then use ArrayBuffer: 192.41ms

$ node -v && node test.js
v17.2.0
Copy into Uint8ClampedArray: 168.555ms
Clone, then use ArrayBuffer: 209.525ms
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda