參考 : http://net.tutsplus.com/tutorials/javascript-ajax/10-ways-to-instantly-increase-your-jquery-performance/
$(function(){
var array = new Array ();
for (var i=0; i<10000; i++) {
array[i] = 0;
}
document.write('<br>'+microtime(true));
var l = array.length;
for (var i=0;i<l; i++) {
array[i] = i;
}
document.write('<br>'+microtime(true));
$.each (array, function (i) {
array[i] = i;
});
document.write('<br>'+microtime(true));
});
function microtime(get_as_float) {
// Returns either a string or a float containing the current time in seconds and microseconds
//
// version: 812.316
// discuss at: http://phpjs.org/functions/microtime
// + original by: Paulo Ricardo F. Santos
// * example 1: timeStamp = microtime(true);
// * results 1: timeStamp > 1000000000 && timeStamp < 2000000000
var now = new Date().getTime() / 1000;
var s = parseInt(now);
return (get_as_float) ? now : (Math.round((now - s) * 1000) / 1000) + ' ' + s;
}
2 則留言:
方便跟效率本來就是互相矛盾的!
非常同意~
張貼留言