;

PDA

Click to See Complete Forum and Search --> : some very strange var benchmark.


omniscient232
03-12-2009, 03:28 PM
Hello,

I wanted to show some benchmarks, because i don't understand why these are the results i get:
in class Ship:
public var wwidth:Number = width;
then:
doing all of these 10000 times, gives this:
craft.x; //11 ms
craft.width;//102 ms
craft.wwidth //1 ms

I cannot believe the amazing difference in performance of this.
And in terms of performance, this means that you can better use a var wwidth, like i did here, as long as your mc doesn't change inn size.

Mavrisa
03-12-2009, 11:16 PM
Going across scope levels takes a lot longer because flash has to do a cross-class look up each time. Setting it to a local variable really improves performance for that reason.

omniscient232
03-13-2009, 11:52 AM
uhm. there isn't a local variable among these three, is there? i don't think i know what you mean.

neznein9
03-13-2009, 12:04 PM
When you call .width it's measuring the size of the object every time - with wwidth you only measure once and then the number is frozen so it's just a memory read.

omniscient232
03-13-2009, 01:23 PM
ok. and x the same?

neznein9
03-13-2009, 01:51 PM
yup.