I'm making an interceptor to log my http requests.
So far, so good, everything is working as expected.
What I want now is to get the time the request took to be executed.
I thought I could do something like this
const start = Date.now();
return next
.handle(req)
.map(res => {
console.log('took ' + (Date.now() - start) + 'ms');
return res;
})
}
But the console shows 1 to 2ms, while the network shows more than 50ms ... I think that I should create the start value right when I create the request, but I don't know how.
Any solution ?
PS : my linting config forbids me to use console.time()
I'm making an interceptor to log my http requests.
So far, so good, everything is working as expected.
What I want now is to get the time the request took to be executed.
I thought I could do something like this
const start = Date.now();
return next
.handle(req)
.map(res => {
console.log('took ' + (Date.now() - start) + 'ms');
return res;
})
}
But the console shows 1 to 2ms, while the network shows more than 50ms ... I think that I should create the start value right when I create the request, but I don't know how.
Any solution ?
PS : my linting config forbids me to use console.time()
1 Answer
Reset to default 6use performance.now()
to measure time duration in milliseconds
var start = performance.now();
return next
.handle(req)
.map(res => {
console.log('took ' + (performance.now() - start) + 'ms');
return res;
})
For futher info check this
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745095967a4610979.html
评论列表(0条)