console.log performance

JavaScript performance comparison

Revision 8 of this test case created by Cody

Preparation code

<div id="container"></div>
      
<script>
Benchmark.prototype.setup = function() {
  var container = document.getElementById("container"),
      obj = {
          one : 1,
          two : 2,
          three : {
              four : 4,
              five : "five",
              six : {
                  seven : [ 8, 9, 10, 11, 12 ],
                  thirteen : [ 14, 15, 16, 17 ]
              },
              eighteen : 18
          },
          nineteen : "nineteen"
  }
  
  function doSomethingAndWriteToLog() {
    for(var i = 0 ; i < 1000 ; i++) {
      var div = document.createElement("DIV");
      var span = document.createElement("SPAN");
      div.appendChild(span);
      container.appendChild(div);
      console.log(i);
    }
  }
  
  function doSomethingAndWriteObjToLog() {
    for(var i = 0 ; i < 1000 ; i++) {
      var div = document.createElement("DIV");
      var span = document.createElement("SPAN");
      div.appendChild(span);
      container.appendChild(div);
      console.log(obj);
    }
  }
  
  function justDoSomething() {
    for(var i = 0 ; i < 1000 ; i++) {
      var div = document.createElement("DIV");
      var span = document.createElement("SPAN");
      div.appendChild(span);
      container.appendChild(div);
    }
  }
  
  function doSomethingAndLogWhenDone(){
    for(var i = 0 ; i < 1000 ; i++) {
      var div = document.createElement("DIV");
      var span = document.createElement("SPAN");
      div.appendChild(span);
      container.appendChild(div);
    }
    console.log("Completed DOM operations!");
  }

};

Benchmark.prototype.teardown = function() {
  container.innerHTML = "";

};
</script>

Preparation code output

<div id="container"></div>

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
iterations with logging
doSomethingAndLogWhenDone();
pending…
iterations without logging
justDoSomething();
pending…
iterations with logging obj
doSomethingAndLogObjWhenDone();
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