1# How to write a good performance test?
2
3## Verify that you wait for all asynchronous code
4
5If your test involves asynchronous code, which is very likely given the DevTools codebase, please review carefully your test script.
6You should ensure that _any_ code ran directly or indirectly by your test is completed.
7You should not only wait for the functions related to the very precise feature you are trying to measure.
8
9This is to prevent introducing noise in the test run after yours. If any asynchronous code is pending,
10it is likely to run in parallel with the next test and increase its variance.
11Noise in the tests makes it hard to detect small regressions.
12
13You should typically wait for:
14* All RDP requests to finish,
15* All DOM Events to fire,
16* Redux action to be dispatched,
17* React updates,
18* ...
19
20
21## Ensure that its results change when regressing/fixing the code or feature you want to watch.
22
23If you are writing the new test to cover a recent regression and you have a patch to fix it, push your test to try without _and_ with the regression fix.
24Look at the try push and confirm that your fix actually reduces the duration of your perf test significantly.
25If you are introducing a test without any patch to improve the performance, try slowing down the code you are trying to cover with a fake slowness like `setTimeout` for asynchronous code, or very slow `for` loop for synchronous code. This is to ensure your test would catch a significant regression.
26
27For our click performance test, we could do this from the inspector codebase:
28```
29window.addEventListener("click", function () {
30
31  // This for loop will fake a hang and should slow down the duration of our test
32  for (let i = 0; i < 100000000; i++) {}
33
34}, true); // pass `true` in order to execute before the test click listener
35```
36
37
38## Keep your test execution short.
39
40Running performance tests is expensive. We are currently running them 25 times for each changeset landed in Firefox.
41Aim to run tests in less than a second on try.