Why is for (var i = 100; i--;) {} much slower (70%) than for (var i = 100; i & # 8594; 0;) {} in Firefox?

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

As you can see, the difference is huge in Firefox, much lower in Safari and missing in Chrome and Opera.

A similar thing happens with loops: http://jsperf.com/whileloopspeed

+4
source share
3 answers

I assume that checking if i (a number) is a false value is more computationally expensive than checking true / false (the result of the comparison).

+2
source

I believe that the internal ToBoolean() , which is executed by the result of the expression, is slightly slower if it is assigned a number compared to the boolean job.

In this test, I get a performance difference when converting to boolean from a logical number and a number with !! .

+2
source

This looks like a problem specific to Jaegermonkey. If I run the test under Tracemonkey, the effect disappears.

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

+2
source

All Articles