测量javascript代码块性能的小知识
快速的测量javascript的性能,我们可以使用console的方法,例如
console.time(label)
和 console.timeEnd(label)
console.time("Array initialize");
var arr = new Array(100),
len = arr.length,
i;
for (i = 0; i < len; i++) {
arr[i] = new Object();
};
console.timeEnd("Array initialize"); // Outputs: Array initialize: 0.711ms
更多内容: Console object, Javascript benchmarking
Demo: jsfiddle - codepen (在浏览器控制台输出)
注意:由于Mozilla不建议将其使用在线上项目中,建议仅在开发中使用。
MEET THE NEW JSTIPS BOOK
You no longer need 10+ years of experience to get your dream job.
Use the 100 answers in this short book to boost your confidence and skills to ace the interviews at your favorite companies like Twitter, Google and Netflix.
GET THE BOOK NOW
MEET THE NEW JSTIPS BOOK
The book to ace the JavaScript Interview.
A short book with 100 answers designed to boost your knowledge and help you ace the technical interview within a few days.
GET THE BOOK NOW