Get #Amazon #Prime for this #holiday #amazonprime #christmas #2019

#JavaScript - performance.now() and console.time()

You can use console.time() or performance.now() to check the time needed to run a block of code or fetch data from a server. From the examples below, you can notice that performance.now() returns a more precise value which is of  DOMHighResTimeStamp type. It is accurate to 5 microseconds.

performance.now()
0.5999999702908099

console time

0.6279296875
You can replace the fetch block with the block of code that you want to measure such as processing JSON data. 

Console.time()

console.time('fetching ip info');
  .then(data => data.json())
  .then(data =>  {
    console.log(data);
  });
console.timeEnd('fetching ip info');



Performance.now()


var t0 = performance.now();
  .then(data => data.json())
  .then(data =>  {
    console.log(data);
  });
var t1 = performance.now();
console.log("Call to fetch ip info took " + (t1 - t0) + "milliseconds.");

Performance now
Performance.now()

Google Chrome Network Analysis

For a network request, you can use network analysis function on Chrome to analyze the traffic. You can read more about network analysis on Google Network Analysis document

Network Analysis
Chrome Network Analysis


Thank you for reading!

Jun