How to calculate response times from AngularJS requests for APIs like get/put/post etc more accurately.
I have intercepted $httpprovider
with a timestamp and use that to calculate the responsetimes. (per this)
But when I look at the response times, the response times are incrementing linearly from the browser barring few initial requests. It seems when I compared with browser, it shows a percentage split in firefox (like blocking, ..waittime.. etc). and this whole sum time seems to be increasing linearly but the actual waittime
is almost about a mean time.
- 1) How can we get the actual
waittime
of the response times as accurately as possible as in browser fromJavascript
? (other than substituting browser with an application?) - 2) Any idea on if how the browser blocks some requests before getting new requests? does it affect the below code's response time calculations?
- 3) In case of Options pre flight request (currently I can use cache for that) but how does that affect httpprovider calculations ? Does Javascript waits for browser before calling the API or JS calls API and then waits until browser completes preflight/blocking etc?
I am providing the links code here again.
app.factory('logTimeTaken', [function() {
var logTimeTaken = {
request: function(config) {
config.requestTimestamp = new Date().getTime();
return config;
},
response: function(response) {
response.config.responseTimestamp = new Date().getTime();
return response;
}
};
return logTimeTaken;
}]);
app.config(['$httpProvider', function($httpProvider) {
$httpProvider.interceptors.push('logTimeTaken');
}]);
$http.get('url').then(function(response) {
var time = response.config.responseTimestamp - response.config.requestTimestamp;
console.log('Time taken ' + (time / 1000) + ' seconds.');
});