Created
June 15, 2012 03:30
-
-
Save learning/2934519 to your computer and use it in GitHub Desktop.
Deff's Device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Duff's Device | |
var iterations = Math.floor(items.length / 8), | |
startAt = items.length % 8, | |
i = 0; | |
do{ | |
switch(startAt){ | |
case 0: process(items[i++]); | |
case 7: process(items[i++]); | |
case 6: process(items[i++]); | |
case 5: process(items[i++]); | |
case 4: process(items[i++]); | |
case 3: process(items[i++]); | |
case 2: process(items[i++]); | |
case 1: process(items[i++]); | |
} | |
startAt = 0; | |
}while(--iterations); | |
// faster version | |
var i = items.length % 8; | |
while(i){ | |
process(items[i++]); | |
} | |
i = Math.floor(items.length / 8); | |
while(i){ | |
process(items[i--]); | |
process(items[i--]); | |
process(items[i--]); | |
process(items[i--]); | |
process(items[i--]); | |
process(items[i--]); | |
process(items[i--]); | |
process(items[i--]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment