Recursion vs iteration - walk tree

JavaScript performance comparison

Revision 12 of this test case created by

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
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);
  }
})(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.

0 Comments