recursivecompare

Benchmark created on


Setup

var arr = []
    for (var i = 0; i < 100000; i++) {
      arr.push("name" + i);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
iterativeLoop
for(let i=0; i < arr.length; i++) {
  console.log(arr[i]);
}
ready
immutableRecursive
const immutableSay = names => {
  "use strict"
  if(names.length) {
    console.log(names.slice(0, 1));
    return immutableSay(names.slice(1, names.length))
  }
};
immutableSay(arr);
ready
mutableRecursive
const say = names => {
  "use strict"
  if(names.length) {
    console.log(names.splice(0, 1));
    return say(names);
  }
};
say(arr);
ready
mutableRecursiveShift
const say = names => {
  "use strict"
  if(names.length) {
    console.log(names.shift());
    return say(names);
  }
};
say(arr);
ready
immutableIterativeForEach
arr.forEach(name => console.log(name))
ready
mutableIterativeLoop
while(arr.length) {
  console.log(arr.shift());
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.