Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

363
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda