console:time() 静态方法

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

备注: 此特性在 Web Worker 中可用。

你可以启动一个计时器来跟踪某一个操作的占用时长。每一个计时器必须拥有唯一的名字,页面中最多能同时运行 10,000 个计时器。当以此计时器名字为参数调用 console.timeEnd() 时,浏览器将以毫秒为单位,输出对应计时器所经过的时间。

关于计时器的细节和示例请参考文档 console

语法

js
time()
time(label)

参数

label

新计时器的名字。用来标记这个计时器,作为参数调用 console.timeEnd() 可以停止计时并将经过的时间在终端中打印出来。

返回值

无(undefined)。

规范

Specification
Console
# time

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
time() static method

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

参见