1

On my project, I would like to optimize an ajax request and to know, on average, how many ms I have gained.

So, thanks to the Google Chrome network tab, I have the time of a request, something like that :

enter image description here

Is there a feature to have some stats about our request ? For example the average time.

If no, how to do that ?

Thanks !

2 Answers2

2

Not too difficult to roll your own code in JavaScript.

var times = [];
var sum = 0;
var tries = 10
for(var i=0; i<tries; i++) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", window.location.href, false);
    xhr.onload = (function() {
        var time = (Date.now() - this.start);
        times.push(time);
        sum += time;
        console.log("#" + this.number + " " + time + "ms");
    }).bind(xhr);
    xhr.number = (i + 1);
    xhr.start = Date.now();
    xhr.send(null);
}
console.log("avg: " + (sum / tries) + "ms");
Louis Ricci
  • 20,804
  • 5
  • 48
  • 62
0

Go to url: chrome://net-internals

Description here

Flash Thunder
  • 11,672
  • 8
  • 47
  • 91