How to test javascript performance time

First, create area where results will be output. You can adjust any style property to fit your needs. Minimum what you need to change is "parentNodeId":

// Test env
function testEnv() {
 var parentNode = document.getElementById("parentNodeId");
 if (parentNode) {
  var testNode = document.createElement("div");
  testNode.id = "testEnv";
  testNode.style.height = "7em";
  testNode.style.backgroundColor = "white";
  testNode.style.overflow = "auto";
  testNode.style.border = "1px solid #778899";
  testNode.style.textAlign = "left";
  testNode.style.overflowX = "hidden";
  testNode.style.whiteSpace = "nowrap";
  parentNode.appendChild(testNode);
 }
}

Then, in the function or any piece of the code you are testing, write:
in the beginning:

var beginTime = new Date().valueOf();

and finally, at the end:

if (document.getElementById("testEnv"))
  document.getElementById("testEnv").innerHTML =
    "execution time: " +
    (new Date().valueOf()-beginTime)/1000 +
    " sec<br/>" +
    document.getElementById("testEnv").innerHTML;

Comments

Popular posts from this blog

Using Trello and Confluence to manage UX design project. Part 2

How do I use InVision

Using Trello and Confluence to manage UX design project. Part 1