Skip to content

Instantly share code, notes, and snippets.

@abelevtsov
Last active March 12, 2019 14:57
Show Gist options
  • Save abelevtsov/c7c4c9ba7c16eabc04b1f9b02b6c868e to your computer and use it in GitHub Desktop.
Save abelevtsov/c7c4c9ba7c16eabc04b1f9b02b6c868e to your computer and use it in GitHub Desktop.
Greenberg's Duff's Device array processing speedup
let iterations = Math.floor(values.length / 8);
let leftover = values.length % 8;
let i = 0;
if (leftover > 0) {
do {
process(values[i++]);
} while (--leftover > 0);
}
if (data.length < 8) {
return;
}
do {
process(values[i++]);
process(values[i++]);
process(values[i++]);
process(values[i++]);
process(values[i++]);
process(values[i++]);
process(values[i++]);
process(values[i++]);
} while (--iterations > 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment