tree test

JavaScript performance comparison

Test case created and last updated

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    function getRandomInt(min, max) {
      return Math.floor(Math.random() * (max - min + 1)) + min;
    }
   
    $test = $('<div id="tree-test"></div>').appendTo('body');
    function render(node) {
      $test.empty();
      $testDiv = $("<div></div>").appendTo($test);
      $("<span>" + node + "</span>").appendTo($testDiv);
    }
   
    nodeCount = 50;
   
    nodes = {0: null, 1: null};
    for(var i = 2; i < nodeCount; i++) {
      nodes[i] = getRandomInt(0, i - 1);
    }
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
recursive version
var orderNodes = function(node) {
  render(node);
  for (var key in nodes) {
    if (key != node && nodes[key] == node) {
      orderNodes(key);
    }
  }
}

for (var key in nodes) {
  if (nodes[key] == null) {
    orderNodes(key);
  }
}
pending…
ordered
for (var key in nodes) {
  render(nodes[key])
}
pending…

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

Compare results of other browsers

0 comments

Add a comment