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?