开发者

javascript speed

开发者 https://www.devze.com 2023-03-16 06:58 出处:网络
On an average system, say Processor: Core 2 Duo 2.2 GHz, Memory: 4 GB How much DOM-manipulations can javascript make?

On an average system, say

Processor: Core 2 Duo 2.2 GHz, Memory: 4 GB

How much DOM-manipulations can javascript make? Is there a way to see how long (开发者_JAVA百科in milliseconds) a simple jQuery action takes? For example one like:

$("#example").css("color","red");


If you're browser supports it, you could use console.profile(); before the call(s) and console.profileEnd(); after. You console should show you output how long it took, the number of calls, etc.

console.profile();
$("#example").css("color","red");
console.profileEnd();

Nettuts+ has a tutorial here.


The process of making these determinations is called "profiling." You can find profilers built into the Chrome Developer Tools, and Firebug for Firefox.


var start = Date.now();

for(var i = 0; i < 10000; i++) { // any number of repetitions
    $("#example").css("color", "red");
}

var end = Date.now();
alert("It took " + Math.round((end - start) / 10000).toString() + " milliseconds on average.");

is how you'd time it. I don't know about DOM actions. You can look in the sizzle.js source to find out exactly what it does, though I know it optimizes for ID selectors and then it depends on the browser. Maybe they traverse the tree in order until they find a matching id. It would be pretty fast.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号