如何从JS Console中的console.timeEnd()获取输出? [英] How to get the output from console.timeEnd() in JS Console?

查看:931
本文介绍了如何从JS Console中的console.timeEnd()获取输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在我的Google Chrome Javascript控制台中获取从 console.timeEnd('t')返回的字符串。

I'd like to be able to get the string returned from console.timeEnd('t') in my Google Chrome Javascript Console.

在下面这个例子中,我想要一个包含t:0.276ms的变量

In this example below, I'd like one variable which would contain "t: 0.276ms"

> console.time('t'); console.timeEnd('t');
  t: 0.276ms
< undefined

这可行吗?

推荐答案

在谷歌浏览器23.0.1262.2(官方版本155904)开发中,看起来这是不可能的。我发现能够准确计算时间的唯一方法是使用 window.performance.webkitNow()

In Google Chrome 23.0.1262.2 (Official Build 155904) dev, it looks like it's impossible. The only way I found to be able to calculate time with accuracy is to use window.performance.webkitNow()

这是一个简单的例子:

var start = window.performance.now();
...
var end = window.performance.now();
var time = end - start;

http://updates.html5rocks.com/2012/08/When-milliseconds-are-not-enough-performance-now

这篇关于如何从JS Console中的console.timeEnd()获取输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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