Javascript performance.now() 与 Date.now()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30795525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
performance.now() vs Date.now()
提问by Lewis
What is the difference between performance.now()and Date.now()?
performance.now()和 和有Date.now()什么区别?
Should I consider performance.now()as a replacement for Date.now()since performace.now()is more consistent and independent?
我应该考虑performance.now()作为替代品,Date.now()因为performace.now()它更加一致和独立吗?
采纳答案by rink.attendant.6
They both serve different purposes.
它们都用于不同的目的。
performance.now()is relative to page loadand more precise in orders of magnitude. Use cases include benchmarking and other cases where a high-resolution time is required such as media (gaming, audio, video, etc.)
performance.now()是相对于页面加载和数量级更精确。用例包括基准测试和其他需要高分辨率时间的情况,例如媒体(游戏、音频、视频等)
It should be noted that performance.now()is only available in newer browsers (including IE10+).
需要注意的performance.now()是,仅适用于较新的浏览器(包括 IE10+)。
Date.now()is relative to the Unix epoch(1970-01-01T00:00:00Z) and dependent on system clock. Use cases include same old date manipulation ever since the beginning of JavaScript.
Date.now()是相对于Unix纪元(1970-01-01T00:00:00Z)并且依赖于系统时钟。用例包括自 JavaScript 开始以来相同的旧日期操作。
See When milliseconds are not enough: performance.nowand nowmethod (Internet Explorer) - MSDNfor more information.
有关更多信息,请参阅当毫秒不够时:performance.now和now方法 (Internet Explorer) - MSDN。
The official W3C spec can be found here: High Resolution Time API
官方 W3C 规范可以在这里找到:高分辨率时间 API
回答by Dreamweaver
Date.now()returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC, performance.now()returns the number of milliseconds, with microseconds in the fractional part, from performance.timing.navigationStart, the start of navigation of the document, to the performance.now()call. Another important difference between Date.now()and performance.now()is that the latter is monotonically increasing, so the difference between two calls will never be negative.
Date.now()返回自 1970 年 1 月 1 日 00:00:00 UTC 以来经过的毫秒数,performance.now()返回毫秒数,小数部分为微秒,从performance.timing.navigationStart文档导航开始到performance.now()调用。Date.now()和之间的另一个重要区别performance.now()是后者是单调递增的,因此两次调用之间的差异永远不会是负数。
For better understanding visit the link.
为了更好地理解,请访问链接。

