2. Use `setInterval` to start your benchmark routine.
3. Benchmark function runs the API using a simple loop that will return quickly (i.e. within 2ms) using performance.now to evaluate.
4. When you obtain enough samples to indicate an alternate path is faster disable the benchmark function
No freezing the browser. Shouldn't take too long to switch to an optimized version.
That being said, this is a lot of complexity / hard to implement in a robust and fast way so I'm not saying it's a better answer.
2. Use `setInterval` to start your benchmark routine.
3. Benchmark function runs the API using a simple loop that will return quickly (i.e. within 2ms) using performance.now to evaluate.
4. When you obtain enough samples to indicate an alternate path is faster disable the benchmark function
No freezing the browser. Shouldn't take too long to switch to an optimized version.
That being said, this is a lot of complexity / hard to implement in a robust and fast way so I'm not saying it's a better answer.