A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: some very strange var benchmark.

  1. #1
    Senior Member
    Join Date
    Jul 2008
    Posts
    418

    some very strange var benchmark.

    Hello,

    I wanted to show some benchmarks, because i don't understand why these are the results i get:
    in class Ship:
    Code:
    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.

  2. #2
    Señor Member Mavrisa's Avatar
    Join Date
    Oct 2005
    Location
    Canada
    Posts
    506
    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.
    Haikus are easy
    But sometimes they don't make sense
    Refrigerator

  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    uhm. there isn't a local variable among these three, is there? i don't think i know what you mean.

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    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.

  5. #5
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    ok. and x the same?

  6. #6
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    yup.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center