English 中文(简体)
为什么(千一=100;一-;){}比(千一=100;一->0;){>>>低得多(70%)。
原标题:Why is for (var i = 100; i--;) {} so much slower (70%) than for (var i = 100; i-->0;) {} in Firefox?

Here s the test: http://jsperf.com/forloopspeed

如你所看到的那样,这一差异在Safari大,在小得多的程度上,以及在 Chrome和歌剧中。

The analogous thing happens with while loops too: http://jsperf.com/whileloopspeed

问题回答

My guess is that checking whether i (a Number) is a falsy value is more computationally expensive than checking true/false (the result of the comparison).

I suppose the internal ToBoolean() that is performed on the result of the expression is a bit slower when being given a number as compared to being given a boolean.

In this test I get a difference in performance when converting to boolean from a boolean vs a number using !!.

这与Jaegermonkey特有的问题一样。 如果我接受“追踪仪基”试验,结果就会消失。

Filed https://bugzilla.mozilla.org/show_bug.cgi?id=670493





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签