This is the time to learn the "high-performance JavaScript" This book, here to record some learning experience and notes ...
The loop iteration of "Duff's Device" optimizes the number of iterations over 1000 cycles.
The functions are as follows:
1 functionDuff (items) {2 if(Items &&items.length) {3 varL = items.length, i = l% 8;4 while(i) {5Console.log (items[--l]);6I--;7 }8i = Math.floor (ITEMS.LENGTH/8);9 while(i) {TenConsole.log (items[--l]); OneConsole.log (items[--l]); AConsole.log (items[--l]); -Console.log (items[--l]); -Console.log (items[--l]); theConsole.log (items[--l]); -Console.log (items[--l]); -Console.log (items[--l]); -I--; + } - } + } A atDuff ([1,2,3,4,5,6,7,8,9,10]);
After function execution, console output: 10 9 8 7 6 5 4 3 2 1
The number of iterations is less than 1000, with little performance improvement. However, more than 1000 times the efficiency of Deff function is significantly improved.
Iterative iteration of JavaScript performance optimization (DUFF)