Duff's device
JavaScript performance comparison
Info
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!
Preparation code
<script>
var iterations = 1000000;
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Regular Loop |
|
pending… |
Duff's Device |
|
pending… |
Fast Duff's Device #1 |
|
pending… |
Fast Duff's Device #2 |
|
pending… |
Fast Duff's Device #3 |
|
pending… |
Fast Duff's Device #4 |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Miller Medeiros
- Revision 8: published
- Revision 9: published
- Revision 10: published by Jamie Mason
- Revision 11: published
- Revision 12: published
- Revision 13: published
- Revision 14: published
- Revision 15: published
- Revision 16: published
- Revision 17: published
- Revision 18: published
- Revision 19: published
- Revision 20: published by Leif Bennett
- Revision 21: published
- Revision 23: published by Jim Montgomery
- Revision 24: published by Nicola Rizzo
0 comments