View Full Version : Execution time

01-27-2011, 05:13 AM
How to know the execution time of a function?

For example, which of these functions run in less time? That is, which of these functions are more weightless to run?

document.getElementById("my_image").src = "images/picture.png";


document.getElementById("my_image").style.webkitTransform = "rotate(45deg)";

Thanks in advance!

Philip M
01-27-2011, 08:49 AM
Count the milliseconds taken to execute the function.

function test() {
var now = new Date()
var start = now.getTime();

// contents of the function here

var now = new Date()
var end = now.getTime();
var diff = end- start;
alert (diff);

In many cases you will find the answer is 0.

Tony McCoy looks between his legs and sees Richard Johnson hard at work ....... Presenter - At The Races