Skip to content

Instantly share code, notes, and snippets.

@learning
Created June 15, 2012 03:30
Show Gist options
  • Save learning/2934519 to your computer and use it in GitHub Desktop.
Save learning/2934519 to your computer and use it in GitHub Desktop.
Deff's Device
// 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