测试 js 方法运行时间
function testFunctionTime(fn) {
var start = new Date().getTime();
if (fn) fn();
var end = new Date().getTime();
console.log(end-start);
}
但当遇上 ajax 和 img.onload 的时候那就很尴尬了...
于是我找到了 console.time(label) 和 console.timeEnd(label),非常 nice !
在开始的地方写上 console.time("测试 fn 速度: ") ,在结束的地方写上 console.timeEnd("测试 fn 速度: ")
label 得相同,然后你就懂了呀