With the Help of console function console.Time() we can measure how long a task in your code takes to run.
// for processing
// for measuring the time and closing
Program 1-
//For starting the Time console
console.time('programming Logic And Code');
// for processing
alert('Click to continue');
// for measuring the time and closing
console.timeEnd('programming Logic And Code');
// for processing
alert('One more time');
// for measuring the time and closing
console.timeEnd('programming Logic And Code');
Output
1- 22.23 ms
2- 34.56 ms
Program 2
var element_programming_logic_code = document.getElementsByTagName('*');
//select all elements on the page
console.time('Loop_time_programming_logic_and_code');
for (var i = 0; i < 5000; i++)
{
for (var j = 0, length = element_programming_logic_code .length; j < length; j++)
{
// nothing to do ...
}
}
console.timeEnd('Loop_time_programming_logic_and_code');
Output:- 1.324 sec
No comments:
Post a Comment