console.timeLog 亦凉 2023-02-21 15:28 1阅读 0赞 I work on a really complex [debugger][] 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 [`console.time` and ][console.time_ and]`console.timeEnd` 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上开发了一个非常复杂的[调试器][debugger] ,但是,不告诉同事,有时我会喜欢简单地使用`console.log`和其他`console`命令来获得一些简单的输出。 我知道,但是,嘿-一切都能完成。 几年前,我详细介绍了[`console.time`和][console.time_ and] `console.timeEnd`用于测量给定任务集的时间。 让我向您展示`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 info console.timeLog("MyApp", "constructor"); // MyApp: 4ms constructor console.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`函数是一种很棒的方式,可以在脚本运行时获取中间时间和信息! > 翻译自: [https://davidwalsh.name/console-timelog][https_davidwalsh.name_console-timelog] [debugger]: https://github.com/devtools-html/debugger.html [console.time_ and]: https://davidwalsh.name/console-time [https_davidwalsh.name_console-timelog]: https://davidwalsh.name/console-timelog
还没有评论,来说两句吧...