node.js中的window.performance.now()等效吗? [英] window.performance.now() equivalent in nodejs?

查看:50
本文介绍了node.js中的window.performance.now()等效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这个问题很直接.

I think the question is straight forward.

我正在寻找类似于nodejs V8引擎中的window.performance.now()的东西.

I'm looking for something that's similar to window.performance.now() in nodejs V8 engine.

现在我正在使用:-

var now = Date.now();
//do some processing..
console.log("time elapsed:", Date.now() - now);

但是,我读到window.performance.now()比使用日期要准确得多,这是因为定义了

But, I read that window.performance.now() is lot more accurate than using the date because of the what's defined here.

推荐答案

我只提到作者在浏览器中优先使用计时API的三个原因似乎并不直接适用于节点情况,第四,Javscript时间的不准确性,引用了2008年的一篇文章,我强烈警告不要依赖旧版本的有关Javascript性能细节的资料,尤其是考虑到最近所有引擎为支持"HTML5"所做的性能改进应用.

I would only mention that three of the reasons the author gives for the preference of the timing API in the browser wouldn't seem to apply directly to a node situation, and the fourth, the inaccuracy of Javscript time, cites an article from 2008, and I would strongly caution against relying on older material regarding Javascript performance specifics, particularly given the recent round of performance improvements all the engines have made to support "HTML5" apps.

但是,在回答您的问题时,您应该查看 process.hrtime()

However, in answer to your question, you should look at process.hrtime()

更新: present 软件包(可通过 npm install获得)礼物)会在 hrtime 周围提供一些糖.

UPDATE: The present package (available via npm install present) provides some sugar around hrtime if you'd like it.

注意: :自节点的版本8.5.0 起,您可以使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆