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

354
Visualizações
How accurate is timing using performance.now() in a Jest test?

I recently discovered a bottleneck in a web application. I was able to whittle down to where it is, by adding some Jest tests which use performance.now() to roughly time the function execution.

 test(...
    const avg = Array(numberOfReps).fill(null).reduce((agg)=>{
                const m0 = performance.now();
                doThing();
                const m1 = performance.now();  
                return agg + ((m1 - m0)/numberOfReps);
            }, 0)  
)

In most cases, I would be comfortable stopping here. But, the bottleneck is in a part of the application that will be used a lot. And, while memos have helped, first-run speed is also very important.

I need to be confident within 2 sigma at 20% that the times reported by my tests are accurate. For example, if my tests report 1000 ms execution, I need to know that 95 percent of executions of size n fall between 800 and 1200 ms.

Does performance testing a la above in Jest fit this bill? I haven't yet been able to find any useful answers elsewhere.

Edit: I'm aware performance.now() is accurate. But, I'm wary that Jest might inject plugins or use some kind of bus that makes the total time less accurate, i.e., executes other functions between m0 and m1. Is that a valid concern?

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

0

PerformanceNow returns a DomHighResTimeStamp.

The time, given in milliseconds, should be accurate to 5 µs (microseconds), with the fractional part of the number indicating fractions of a millisecond. However, if the browser is unable to provide a time value accurate to 5 µs (due, for example, to hardware or software constraints), the browser can represent the value as a time in milliseconds accurate to a millisecond.

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