这段代码加到前端页面,拿到数据后传给后端,就可以统计性能测试数据
const per = window.performance;
console.log(`内存占用:${(per.memory.usedJSHeapSize/1024/1024).toFixed(2)}mb`)
console.log(`TCP连接耗时:${per.timing.connectEnd - per.timing.connectStart}ms`)
console.log(`响应耗时:${per.timing.responseEnd - per.timing.responseStart}ms`)
window.onload = function () {
console.log(`DOM渲染耗时:${per.timing.domComplete - per.timing.domLoading}ms`)
}
网友评论