console.log performance (v2)

Revision 2 of this benchmark created on


Description

Checking to see how leaving console.log statements in your JS code impacts performance.

Preparation HTML

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

Setup

var container = document.getElementById("container");
    
    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 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!");
    }

Teardown


    container.innerHTML = "";
  

Test runner

Ready to run.

Testing in
TestOps/sec
iterations with logging
doSomethingAndWriteToLog();
ready
iterations without logging
justDoSomething();
ready

Revisions

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