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

298
Visualizações
JS: setInterval has weird behavior with chrome throttling

I was testing my website out with chrome throttling, using the low-end mobile. I noticed one of my JS intervals were running much slower than it should be for no reason. I decided to investigate further, so I wrote this code:

let prev = Date.now();
let x = 0;
setInterval(() => {
  if(x++ % 100 == 0) {
    console.log(Date.now() - prev);
    prev = Date.now();
  }
}, 10);

It sets an interval to run every 10ms, and it prints the time elapsed every 100 runs. This should be 1 second, but it is printing 4-8 seconds. This shouldn't happen, because getting the date every 100 runs, and then logging it, should be a piece of cake, even for "low-end mobile".

My best guess right now is that chrome's throttling also specifically throttles the event loop, which sometimes gives misleading results, like here. Is this true?

about 4 years ago · Juan Pablo Isaza
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