Below is just a pseudo answer, which I hope can be updated by the community. It was originally a comment, but it got too long, too fast, and therefore had to be sent as an answer.
Interesting / Results
In running several tests , I could not find any correlation with console.log . Testing in OSX Safari I found that the problem arose with and without printing to the console.
What I noticed was a pattern. When I approached 2147483648 (2 ^ 31), you got an excess from the initial starting value. It most likely depends on the user environment, but I found an inflection point around 2147485000 (try the numbers above and below: 2147430000..2147490000). Somewhere near this number, where the timings have become more uniform.
I really hoped it would be 2 ^ 31 [for sure], since this number is also significant in computer terms; this is the upper bound of the integer long . However, my tests led to a number that was slightly larger (for reasons unknown at the moment). Besides checking that the page file was not used, I did not do another memory analysis.
CHANGE from user:
In my setup, this is actually exactly 2 ^ 31 where the transition occurs. I tested it while playing with the following code:
http://jsfiddle.net/8w24v/
This information may support the observation of Derek's initialization.
This is just a thought and can be stretched:
LLVM or something else may perform some preliminary optimizations. Perhaps the loop variable begins as an int , and then after passing through two or two, the optimizer notices that the variable becomes long . When trying to optimize, he tries to set it as a long front, only in this case it is not an optimization that saves time, since working with a regular integer is better than the cost of converting from int to long.
I would not be surprised if the answer was somewhere in ECMAScript :)
vol7ron
source share