I work on a really complex at Mozilla but, and don't tell my colleagues, I sometimes enjoy simply using console.log
and other console
commands to get some simple output. I know, I know, but hey -- whatever gets the job done. A few years ago I detailed for measuring time for a given set of tasks; let me show you
console.timeLog
, a new function in Firefox Nightly for logging events during a console.time
timer!
我在Mozilla上开发了一个非常复杂的 ,但是,不告诉同事,有时我会喜欢简单地使用console.log
和其他console
命令来获得一些简单的输出。 我知道,但是,嘿-一切都能完成。 几年前,我详细介绍了 用于测量给定任务集的时间。 让我向您展示
console.timeLog
,这是Firefox Nightly中的一项新功能,用于在console.time
计时器期间记录事件!
Start by kicking off the timer with a name of your choice:
首先使用您选择的名称启动计时器:
console.time("MyApp");
Whenever you want the intermediate timer value, as well as extra information like variable or object values, you can use console.timeLog
:
每当您需要中间计时器值以及诸如变量或对象值之类的额外信息时,都可以使用console.timeLog
:
// Same timer name, provide sublabel and optional infoconsole.timeLog("MyApp", "constructor"); // MyApp: 4ms constructorconsole.timeLog("MyApp", "render", this.state);// MyApp: 2ms render Object { disabled: false }
When your timed tasks have completed, you can call console.timeEnd
to stop the timer:
定时任务完成后,可以调用console.timeEnd
停止计时器:
console.timeEnd("MyApp");// MyApp: 10ms
Firefox has a Performance tab for very detailed performance metrics but, as always, the console is a great way to get some basic insight at a glance. The timeLog
function is an awesome way to get intermediate timing and information while your script runs!
Firefox的“性能”选项卡提供了非常详细的性能指标,但是与往常一样,控制台是一目了然的基本了解的好方法。 timeLog
函数是一种很棒的方式,可以在脚本运行时获取中间时间和信息!
翻译自: