Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 11th, 2012  |  syntax: None  |  size: 0.68 KB  |  hits: 4  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Javacscript: Calculating the time required to retrieve data
  2. $.post("test.php", function(data) {
  3.    //do something with data
  4.  });
  5.        
  6. var start = new Date().getTime();
  7.  
  8. $.post("test.php", function(data) {
  9.    //do something with data
  10.  
  11.    var end = new Date().getTime();
  12.  
  13.    alert((end - start) + ' milliseconds passed');
  14. });
  15.        
  16. var before = new Date();
  17. $.post("test.php", function(data) {
  18.    var timeTook = new Date() - before;
  19.  });
  20.        
  21. var start = Date.now();
  22.  
  23. $.post("test.php", function(data) {
  24.     alert(Date.now() - start);
  25. });
  26.        
  27. if (!Date.now)
  28.     Date.now = function() {
  29.         return +(new Date);
  30.     };
  31.        
  32. var start = new Date();
  33.        
  34. var end = new Date();
  35. alert(end - start);