jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Simple test of variations of loop unrolling/unwinding based on the original Duff's Device.
Result may vary based on the number of iterations, browser, OS and external influences...
Usually Fast Duff's Device #2, #3, #4 runs faster when the number of iterations is bigger or when the test is executed multiple times without browser refresh - bitwise operations have a really strange behavior in JS, sometimes they are really fast and other times they run slower than the Math
methods.
Make sure you test each approach using real application code (since results may vary) and just use this kind of optimization if you really need it! Try to combine techniques and avoid property lookups!
PS: It's over 9000 iterations!
<script>
var iterations = 99999;
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Regular Loop |
| ready |
Duff's Device |
| ready |
Fast Duff's Device #1 |
| ready |
Fast Duff's Device #2 |
| ready |
Fast Duff's Device #3 |
| ready |
Fast Duff's Device #4 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.