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 以来经过的毫秒数。

startMark 参数可以标识性能时间轴中的任何现有的 PerformanceMark,或者可能标识由 PerformanceNodeTiming 类提供的任何时间戳属性。 如果指定的 startMark 不存在,则抛出错误。

可选的 endMark 参数必须标识性能时间轴中的任何现有的 PerformanceMarkPerformanceNodeTiming 类提供的任何时间戳属性。 不传入参数则 endMarkperformance.now(),否则如果命名的 endMark 不存在,则抛出错误。

创建的 PerformanceMeasure 条目放入全局的性能时间轴,可以用 performance.getEntriesperformance.getEntriesByNameperformance.getEntriesByType 查询。 当执行观察时,应使用 performance.clearMeasures 手动从全局的性能时间轴中清除条目。

  • name <string>
  • startMarkOrOptions <string> | <Object> Optional.
    • detail <any> Additional optional detail to include with the measure.
    • duration <number> Duration between start and end times.
    • end <number> | <string> Timestamp to be used as the end time, or a string identifying a previously recorded mark.
    • start <number> | <string> Timestamp to be used as the start time, or a string identifying a previously recorded mark.
  • endMark <string> Optional. Must be omitted if startMarkOrOptions is an <Object>.

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.

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.

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.

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.