Posted By

1man on 07/03/09


Tagged

console function firebug timing


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


Function Timing Example (includes jQuery)


 / Published in: jQuery
 

URL: http://is.gd/1mhJr

A way to time how long it takes to get through a certain block of code. Good way to measure performance on the page.

You could also use the built in logging functions in firebug. Not sure how they would tally up in a test.

  1. $(function(){
  2. console.info("Start Test");
  3. var d = new Date();//Get our start time
  4. console.info(d.getSeconds() + " " + d.getMilliseconds());
  5.  
  6. //Run our test
  7. var testBody = "";
  8. for (var i=0; i<1000; i++){
  9. testBody += "<div class='testable"+i+"'>";
  10. }
  11. $("body").append(testBody);
  12. for (var j=0; j<1000; j++){
  13. $(".testable"+j);
  14. }
  15.  
  16. var d = new Date();//Get our end time
  17. console.info(d.getSeconds() + " " + d.getMilliseconds());
  18. console.info("End Test");
  19. /**
  20. * Console will now log 2 times, the difference between
  21. * them is how long the test took to run
  22. */
  23. });

Report this snippet  

You need to login to post a comment.