Skip to content

Instantly share code, notes, and snippets.

@kangax
Created March 3, 2009 19:02
Show Gist options
  • Select an option

  • Save kangax/73456 to your computer and use it in GitHub Desktop.

Select an option

Save kangax/73456 to your computer and use it in GitHub Desktop.
var arr = [1,2,3,4,5,6,7,8,9,10],
lim = 1000;
function iterator(sum, n) {
return n += sum;
}
console.time(1);
for (var i=0; i<lim; i++) arr.inject(0, iterator);
console.timeEnd(1);
console.time(2);
for (var i=0; i<lim; i++) Array.reduce(arr, iterator);
console.timeEnd(2);
/*
FF 3.0.6
1: 58ms
2: 8ms
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment