Recursion vs iteration - walk tree

JavaScript performance comparison

Test case created

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/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();
}
pending…
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);
  }
}

visitNode(100);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment