views:

104

answers:

1

Which of these 3 is the fastest (least CPU cycles) on the AVM2 in ActionScript 3?

Object(instance).constructor

(instance as Object).constructor

instance["constructor"]

I would do some tests, but I have no idea how to accurately profile that kind of thing.

+5  A: 
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
performancetests.Constructors (5 iterations, 5,000,000 loops through each)                            
Player version: MAC 10,0,32,18 (debug)
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
method...................................................ttl ms...avg ms
instanceAsObjectConstructor                                9516  1903.20
instanceBracketConstructor                                 6941  1388.20
objectDotConstructor                                       9916  1983.20
––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––

I used Grant Skinner's AS3 Performance test harness and got these results.

Joel Hooks
This must be because the instanceBracketConstructor is the only one that doesn't cast the instance. Otherwise this result would scare me.
dlamblin