performance.measure(name[, startMarkOrOptions[, endMark]])


  • name <string>
  • startMarkOrOptions <string> | <Object> 可选。
    • detail <any> 可选的附加细节,用于测量。
    • duration <number> 开始和结束时间之间的持续时间。
    • end <number> | <string> 用作结束时间的时间戳,或标识先前记录标记的字符串。
    • start <number> | <string> 用作开始时间的时间戳,或标识先前记录标记的字符串。
  • endMark <string> 可选。如果 startMarkOrOptions 是一个 <Object>,则必须省略。

在性能时间轴中创建一个新的 PerformanceMeasure 条目。PerformanceMeasurePerformanceEntry 的子类,其 performanceEntry.entryType 始终为 'measure',而其 performanceEntry.duration 用于测量从 startMarkendMark 经过的毫秒数。

【Creates a new PerformanceMeasure entry in the Performance Timeline. A PerformanceMeasure is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'measure', and whose performanceEntry.duration measures the number of milliseconds elapsed since startMark and endMark.】

startMark 参数可以识别性能时间线中任何 已存在的 PerformanceMark,也可以识别 PerformanceNodeTiming 类提供的任何时间戳属性。如果指定的 startMark 不存在,则会抛出错误。

【The startMark argument may identify any existing PerformanceMark in the Performance Timeline, or may identify any of the timestamp properties provided by the PerformanceNodeTiming class. If the named startMark does not exist, an error is thrown.】

可选的 endMark 参数必须标识性能时间线中任何 已存在PerformanceMark,或 PerformanceNodeTiming 类提供的任何时间戳属性。如果未传递该参数,endMark 将为 performance.now();否则,如果指定的 endMark 不存在,将抛出错误。

【The optional endMark argument must identify any existing PerformanceMark in the Performance Timeline or any of the timestamp properties provided by the PerformanceNodeTiming class. endMark will be performance.now() if no parameter is passed, otherwise if the named endMark does not exist, an error will be thrown.】

创建的 PerformanceMeasure 条目会被放入全局性能时间线中,并且可以通过 performance.getEntriesperformance.getEntriesByNameperformance.getEntriesByType 进行查询。当执行观察时,应使用 performance.clearMeasures 手动清除全局性能时间线中的条目。

【The created PerformanceMeasure entry is put in the global Performance Timeline and can be queried with performance.getEntries, performance.getEntriesByName, and performance.getEntriesByType. When the observation is performed, the entries should be cleared from the global Performance Timeline manually with performance.clearMeasures.】