Recursion vs iteration - walk tree (v12)

Revision 12 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Iterate through tree - simulation
// simulates operations for walking through tree using iteration
var stack = [],
  i, max = 100;

// push not yet processed nodes to stack
for (i = 0; i < max; i++) {
  stack.push(i);
}

// process remaining nodes from stack
while (stack.length > 0) {
  var x = stack.pop();
}
ready
Recurse through tree - simulation
// simulates operations for walking through tree recursively
(function visitNode(i) {
  if (i > 0) {
    // do recursion till the leave node is not reached
    visitNode(i - 1);
  }
})(100);
ready

Revisions

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