I want to time the whole program to finish its process, I need that time for comparison. Is there any easy way to implement this?
I want to time the whole program to finish its process, I need that time for comparison. Is there any easy way to implement this?
Do this:
console.time('teste');
for (var i = 0; i < 10000; i++) {
// seu código aqui
}
console.timeEnd('teste');
In this case, your code will run 10000 times and in the end you will know how much time has passed. Very useful for comparing codes to know which is the most efficient, p. ex:
console.time('teste1');
for (var i = 0; i < 10000; i++) {
$('#painel .lista');
}
console.timeEnd('teste1');
console.time('teste2');
for (var i = 0; i < 10000; i++) {
$('#painel').find('.lista');
}
console.timeEnd('teste2');
In this example, you find out which snippet is most efficient: $('#painel .lista')
or $('#painel').find('.lista')
, using jQuery.
See also: link