我的 node.js 应用程序中的一个功能是使用 fetch 函数调用外部 API。我正在尝试找到最准确的方法来测量所述 API 的响应时间。
我正在使用“日期”方法来做到这一点:
let start_time = new Date().getTime();
fetch('https://jsonplaceholder.typicode.com/posts/1')
.then((res) => {
return res.json();
})
.then((data) => {
console.log('Response time:', new Date().getTime() - start_time);
有没有更好\更准确的方法来获取?