ID:153259
 
I wonder if anyone into the details could answer this question: When you run a loop and create a var within the loop, is it slower than to put it outside?

In other words, is:
var/a = 0
while(a++ < 10000)
var/b = rand(1,100)
world << b


Slower than:
var
a = 0
b = 0

while(a++ < 10000)
b = rand(1,100)
world << b


Crude example I know, but you get my point.


/Gazoot
Creating vars inside probably gives you construction and deletion overhead. Creating vars outside probably gives another level of scope to search in. I'm going to guess that new var overhead takes equal or more time than a level of scope in a loop large enough to matter. In other words, it's likely... I think.