ReferenceError: performance is not defined when using performance.now()(ReferenceError:使用 performance.now() 时未定义性能)
问题描述
我在尝试使用 ReferenceError: performance is not definedPerformance/now" rel="noreferrer">performance.now() 来衡量一个函数调用的执行时间:
I am getting an error ReferenceError: performance is not defined
when trying to use performance.now() to measure the execution time of a function call:
export async function find(someId: string, ctx: context.IContext) {
try {
var t0 = performance.now();
var res = someModel.find(someId, ctx.cookies);
var t1 = performance.now();
console.log("Call to find took " + (t1 - t0) + " milliseconds.");
return res;
} catch (err) {
console.error(err);
throw err;
}
}
有什么办法可以解决这个问题吗?
Any ideas how I can fix this?
推荐答案
我知道这是标记为前端,但如果有人遇到这个寻找 node.js 解决方案(如我),你需要首先要求性能perf_hooks 模块(在节点 8.5+ 中可用).
I know this is tagged front-end but if anyone comes across this looking for a node.js solution (like me), you need to first require performance from the perf_hooks module (available in node 8.5+).
const {performance} = require('perf_hooks');
const t0 = performance.now();
...
这篇关于ReferenceError:使用 performance.now() 时未定义性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ReferenceError:使用 performance.now() 时未定义性能


基础教程推荐
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01