console.timeLog

发布于:2021-02-10 00:00:26

0

420

0

调试器 console

我在Mozilla上使用一个非常复杂的调试器,但是我不告诉我的同事,我有时喜欢简单地使用console.log和其他控制台命令来获得一些简单的输出。我知道,但只要能搞定就行。几年前我详细介绍了控制台。时间和控制台。timeEnd用于测量给定任务集的时间;让我给你看看控制台。timeelog, Firefox中的一个新功能,用于每晚记录控制台期间的事件。时间计时器!

首先使用您选择的名称启动计时器:

console.time("MyApp");

每当您需要中间计时器值以及诸如变量或对象值之类的额外信息时,都可以使用console.timeLog:

// Same timer name, provide sublabel and optional info console.timeLog("MyApp", "constructor");  // MyApp: 4ms constructor console.timeLog("MyApp", "render", this.state); // MyApp: 2ms render Object { disabled: false }

定时任务完成后,您可以调用console.timeEnd 停止计时器:

console.timeEnd("MyApp"); // MyApp: 10ms

Firefox的“性能”选项卡提供了非常详细的性能指标,但与往常一样,控制台是一目了然的基本了解的好方法。该timeLog 功能是一种在脚本运行时获取中间时间和信息的绝佳方法!