javascript - 比较性能API和chrome的开发者工具的计时结果时的差异
问题描述
我正在尝试计时fetch
。以下屏幕截图显示了 chrome 开发人员工具针对特定获取请求显示的时间。
从红色标记的请求可以看出,它花费的总时间是79 milliseconds
. 看起来不错。
当我尝试使用性能 api计时时,毫秒超过 100% 163.46000001067296 ms
。怎么会这样?
这是我正在做的事情:
loadInitVariables() {
const queryString = this.formQueryString(this.queryStringParams);
const t0 = performance.now(); // TIMESTAMP ONE @ T0
return fetch(`${this.initVariablesPath}${queryString}`, {
method: "get",
headers: { "Content-Type": "application/json" },
})
.then(response => {
const t1 = performance.now(); // TIMESTAMP 2 @ T1
log.debug(`Loaded init vars in ${t1 - t0} ms.`);
return response.json();
})
}
为什么会有这种差异?如果它可能是几毫秒,即 +10 - +20,那会没问题,但它会超过 100%。
我没有正确测量这个吗?
解决方案
推荐阅读
- python - 在python中以多个线程下载文件时,线程在所有文件可用之前完成
- cocoapods - “GMSPlace”类型的值在 GooglePlaces Cocoapod 3.3.7 中没有成员“视口”
- html - 为什么 jasmine 单元测试中 document.getElementsByClassName() 的结果为空?
- arrays - 使用序列化键和值将多维数组转换为单个数组
- java - 如何纠正 DrawersLayout?
- javascript - 初始化拖放项目中的项目数据
- php - 在 reactJs 中调用 axios 的问题
- java - SQLite MVVM在Activity中返回&获取rowId
- azure - ADLA 作为 Power BI 的来源
- mysql - 如何从 Ubuntu VM 访问在 windows localhost:3006 上运行的 Mysql 数据库