Mozilla比Internet Explorer更快 [英] Mozilla faster than Internet Explorer

查看:61
本文介绍了Mozilla比Internet Explorer更快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我用javascript开发了一个日历程序,直到现在我已经完成了大部分测试使用Mozilla和Firefox。一切正常工作

罚款,但是当我尝试使用Internet Explorer时,我的响应时间是

有时比使用Mozilla慢50倍。


我知道我没有给你很多东西,但我不是在寻找一个回答问题的方法来解决这个问题。例如,

有没有人在这里知道一个好的网站,它处理

浏览器特定的javascript性能问题?


提前感谢任何有用的提示。

解决方案

dhplank写道:

大家好,
我已经用javascript开发了一个日历程序,直到现在我已经使用Mozilla和Firefox完成了大部分测试。一切正常,但是当我尝试使用Internet Explorer时,我的响应时间有时比使用Mozilla慢50倍。

我知道我没有给你太多过去,但我不是在寻找一个解决问题的方法。例如,
这里有没有人知道一个好的网站,它处理特定于浏览器的javascript性能问题?




IE之间的性能差异有时可以在意想不到的地方找到Firefox和b $ b。一种策略是隔离循环并测试它们,然后将它们分成两半,然后再分成两半等,直到找到

真正慢的位。


更换循环如:


for(var i = 0; i< someThing.length; i ++)

// mess with someThing [i]

}


with:


var i = 0,x = someThing [i ];

做{

//混乱x

}而((x = someThing [++ i]))


可以显着缩短处理时间,特别是对于某些Thing.length的大值。


IE往往是在DOM操作中比Firefox慢,但是对于其他一些东西(特别是字符串中的字符串)可以更快地获得



一旦你找到了缓慢的位,把它们发布在这里,你可能会更好地获得
更好的东西,或者只是发布一些你认为可能是原因的循环。

-

Rob

< snip>

更换循环如下:


for(var i = 0; I< someThing.length; i ++)

//搞乱someThing [i]

}


with:


var i = 0,x = someThing [i];

做{

//混乱x

}而(( x = someThing [++ i]))


< snip>


这是一个值得注意的差异?


mike写道:

< snip>
更换循环如:

for(var i = 0; i< someThing.length; i ++)
//搞乱someThing [i]
}

: />
var i = 0,x = someThing [i];
做{
//搞乱x
}而((x = someThing [++ i]) )

< snip>

这是一个值得注意的差异?




只有当'某些事情与某些事情一起重复[i]''多次重复表达时,例如

内循环内部。


简单地用以下代码替换for循环:


for(var i = 0; i< someThing.length; i ++){

var x = someThing [i];

//混乱x

}


将提供相同的速度提升而不会相应地降低

的可读性。


还有另一种方法,do..while循环给出了大幅加速

虽然:


如果任何数组元素都有非真值,while循环将退出

when它击中第一个,而for循环将继续通过

整个数组。显然,在一次迭代后中止循环而不是
10,000将会产生明显的差异。 :^)


Hello everyone,

I''ve developed a calendar program in javascript, and up until now I''ve
done most of my testing using Mozilla and Firefox. Everything works
fine, but when I try to use Internet Explorer my response time is
sometimes 50 times slower than using Mozilla.

I know I haven''t given you much to go by, but I''m not looking for an
answer so much as an approach to debugging the problem. For example,
does anyone here know of a good web site which deals with
browser-specific javascript performance issues?

Thanks in advance for any helpful hints.

解决方案

dhplank wrote:

Hello everyone,

I''ve developed a calendar program in javascript, and up until now I''ve
done most of my testing using Mozilla and Firefox. Everything works
fine, but when I try to use Internet Explorer my response time is
sometimes 50 times slower than using Mozilla.

I know I haven''t given you much to go by, but I''m not looking for an
answer so much as an approach to debugging the problem. For example,
does anyone here know of a good web site which deals with
browser-specific javascript performance issues?



Performance differences between IE and Firefox can sometimes be found
in unexpected places. One strategy is to isolate loops and test
them, then split them in half, then half again, etc. until the
really slow bits are found.

Replacing loops like:

for (var i=0; i<someThing.length; i++)
// mess with someThing[i]
}

with:

var i=0, x=someThing[i];
do {
// mess with x
} while ( ( x = someThing[++i] ) )

can cause dramatic reductions in processing time, particularly for
large values of someThing.length.

IE tends to be slower than Firefox at DOM operations, but can be
much faster with some others (particularly string stuff in places).

Once you''ve found the slow bits, post them here and you''ll likely get
something better, or just post some of your loops that you think may
be the cause.
--
Rob


<snip>
Replacing loops like:

for (var i=0; i<someThing.length; i++)
// mess with someThing[i]
}

with:

var i=0, x=someThing[i];
do {
// mess with x
} while ( ( x = someThing[++i] ) )

<snip>

Is this a "Noticeable" difference?


mike wrote:

<snip>
Replacing loops like:

for (var i=0; i<someThing.length; i++)
// mess with someThing[i]
}

with:

var i=0, x=someThing[i];
do {
// mess with x
} while ( ( x = someThing[++i] ) )

<snip>

Is this a "Noticeable" difference?



Only if ''// mess with someThing[i]'' repeats the expression many times, e.g.
inside an inner loop.

Simply replacing the for loop with:

for (var i=0; i<someThing.length; i++) {
var x = someThing[i];
// mess with x
}

will give the same speed improvements without the corresponding drop in
readability.

There is one other way that the do..while loop gives a massive speed boost
though:

if any of the array elements have non-true values the while loop will exit
when it hits the first one whereas the for loop will continue through the
whole array. Obviously aborting the loop after a single iteration instead
of 10,000 would give a noticeable difference. :^)


这篇关于Mozilla比Internet Explorer更快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆