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
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!
var iterations = 8;
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Fast Duff's Device #1
Fast Duff's Device #2
Fast Duff's Device #3
Fast Duff's Device #4
Compare results of other browsers
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
- Revision 28: published
- Revision 29: published by Esailija
- Revision 30: published
- Revision 31: published by Jörg Schaper and last updated
- Revision 32: published by Jörg Schaper
- Revision 33: published by Jörg Schaper
- Revision 34: published
- Revision 35: published by Jörg Schaper