首页/前端性能优化/如何测试网页js性能console.time()及console.timeEnd()

如何测试网页js性能console.time()及console.timeEnd()

发布-xiaoming | 浏览量-

之前一直在找可以测试javascript效率的工具,看了JSLitmus、以及大名鼎鼎的jsunit。很强大,但是说实话并不是很直观,当然方便就更谈不上了,其实最简单的工具就藏在我们身边。

firebug相信每个web开发者必备的工具之一,也是最方便最好用的工具,对我来说没有之一。可能你经常的去使用它控制输出语句console.info ,其实它有更多的东西等着我们去挖掘,详见firebug console API。而我们今天讨论的是它一个容易被我们忽视的命令console.time()。使用方法也异常简单,先看看firebug api的介绍。

console.time(name)
Creates a new timer under the given name. Call console.timeEnd(name) with the same name to stop the timer and print the time elapsed..
console.timeEnd(name)
Stops a timer created by a call to console.time(name) and writes the time elapsed.

用法如下:

console.time(‘name’)
//写下你要测试的代码
console.timeEnd(‘name’)

原文地址:http://www.35ui.cn/post/20140625369.html

标签

上一条: jQuery中的循环技巧
下一条: 如何编写自己的JQUERY插件

或许你还对下面的文章感兴趣