How do you time a job until it’s over?

Asked

Viewed 298 times

1

I want to time the entire program to complete its process, I need that time for comparison. Is there any easy way to implement this?

  • related http://answall.com/questions/55867/calcular-quanto-tempo-demora-pra-executar-fun%C3%A7%C3%A3o

1 answer

0


Do so:

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 at the end you know how much time has passed. Very useful for comparing codes to know which is the most efficient, e. g:

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 above, you find out which stretch is the most efficient: $('#painel .lista') or $('#painel').find('.lista'), using jQuery.


See also: /a/55872/622

Browser other questions tagged

You are not signed in. Login or sign up in order to post.