Console.timeLog() - Web API 接口参考 编辑

在控制台输出计时器的值,该计时器必须已经通过 console.time() 启动。

参阅文档中的 Timers 部分获取详细说明和示例。 

Note: 此特性在 Web Worker 中可用。

语法

console.timeLog(label);

参数

label
计时器索引。

返回值

如果没有传入 label 参数,则以 default: 作为引导返回数据:

default: 1042ms

如果传入了一个已经存在的 label ,则会以 label:  作为引导返回数据:

label: 1242ms

异常

如果计时器未启动, timeLog() 会返回一个警告:

Timer “default” doesn’t exist.

如果传入的 label 索引没有与之对应的计时器,则返回如下警告:

Timer “timer name” doesn’t exist. 

示例

console.time("answer time");
alert("Click to continue");
console.timeLog("answer time");
alert("Do a bunch of other stuff...");
console.timeEnd("answer time");

上例中的输出分别显示了用户从打开页面到关闭第一个 alert 和第二个 alert 框的时间间隔:

注意:使用 timelog() 输出计时器的值会显示计时器名称。使用 timeEnd() 停止也会显示计时器名称和输出计时器的值,并且,最后的 " - timer ended" 可以清楚的显示计时器不再计时的信息。

规范

规范状态注释
Console API
console.timeLog()
Living StandardInitial definition

浏览器兼容性

BCD tables only load in the browser

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

相关文档

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:90 次

字数:3648

最后编辑:8 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文