-
2007-12-27
javascript在不同的浏览器的效能
版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://snk.blogbus.com/logs/12800652.html
javascript在不同的浏览器的效能是不一样的。而且相差很远。
看看高手们做出的比较吧。
the SunSpider benchmark: 一个综合易用的 javascript 比较程序网页。
3d Pure JavaScript computations of the kind you might use to do 3d rendering, but without the rendering. This ends up mostly hitting floating point math and array access. access Array, object property and variable access. bitops Bitwise operations, these can be useful for various things including games, mathematical computations, and various kinds of encoding/decoding. It's also the only kind of math in JavaScript that is done as integer, not floating point. controlflow Control flow constructs (looping, recursion, conditionals). Right now it mostly covers recursion, as the others are pretty well covered by other tests. crypto Real cryptography code, mostly covers bitwise operations and string operations. date Performance of JavaScript's "date" objects. math Various mathematical type computations. regexp Regular expressions. Pretty self-explanatory. string String processing, including code to generate a giant "tagcloud", extracting compressed JS code, etc. 
下面的程序在 FF 不需要 1s,在 IE 需要 30s以上。
var d = new Date();
var s = "a";
for(i=1;i<100000;i++){
s=s+"a";
}
alert(new Date()-d);
同样的效果的代码这个在IE运行的就很快,不需要 1s。
var d = new Date();
var a = new Array();
for(i=1;i<100000;i++){
a[i]="a";
}
var s = a.join("");
alert(new Date()-d);
所以大家写 javascript的时候真的要好小心,除了是否能跨浏览器运行,还要考虑写法和效能的问题。
随机文章:
replace 方法 2009-02-12Use firebug lite in IE 2008-11-20使用Firebug 2007-11-15當 prototype 指向自己時,就不會從 prototype 搜尋 2007-03-05更改浏览器的标题 2007-03-01
收藏到:Del.icio.us








评论