Hi Pan,

here is a little test, i can't see big differences:

<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    creationComplete="onCreationComplete()"
    >
    <mx:Script>
        <![CDATA[
       
            import flash.utils.getTimer;
            import test.MyData;
           
           
            [Bindable]
            private var result : String;
           
            private function onCreationComplete() : void
            {
                var count : int = 10000000;

                var md : MyData = new MyData();
                var a : Array = new Array( md );
               
                var i : int;
                var time : int;
               
               
                //-----------------------
                time = getTimer();
                for( i = 0; i < count; i++ )
                {
                    a[0].prop = 3;
                }
                var t1 : int = getTimer() - time;
               
                //-----------------------
                time = getTimer();
                for( i = 0; i < count; i++ )
                {
                    MyData(a[0]).prop = 3;
                }
                var t2 : int = getTimer() - time;
                //-----------------------
                time = getTimer();
                for( i = 0; i < count; i++ )
                {
                    (a[0] as MyData).prop = 3;
                }
                var t3 : int = getTimer() - time;
               
                result = "t1: " + t1 + " t2:" + t2 + " t3:" + t3;
            }
           
          ]]>
    </mx:Script>   
   
    <mx:Text text="{result}"/>
   
</mx:Application>


Cheers,
Ralf.



On 8/8/06, Pan Troglodytes < [EMAIL PROTECTED] > wrote:
Thanks for the reply, Matt.  Is there any performance difference between all three?  I'm curious if doing any casting at all is a performance hit.


On 8/7/06, Matt Chotin <[EMAIL PROTECTED]> wrote:

I don't think there should be a performance difference between the two.

 

Matt

 


From: [email protected] [mailto:[email protected]] On Behalf Of Pan Troglodytes
Sent: Monday, August 07, 2006 9:21 AM
To: flexcoders
Subject: [flexcoders] any performance hit using "as"?

 

I tend to like to make my code autosense for me, so sometimes I do things like this:

MyObjectType(grid.selectedItem).somefield = 3;

I assume that adds no overhead, since it is a straight cast (though I could be wrong), since I have seen runtime errors specifically telling me my cast was wrong.  But sometimes with Array, I have to use "as" because it gets a cast confused with a new array contructor.  So I'm wondering what the difference in performance is, if any.

Given then grid.selectedItem is MyObjectType, consider the following statements:

grid.selectedItem.somefield = 3;
MyObjectType(grid.selectedItem).somefield = 3;
(grid.selectedItem as MyObjectType).somefield = 3;


Is there any runtime performance difference to them?  I only just now read the help on "as" I noticed that if it is NOT the desired type, it returns null.  That totally messes with my brain, coming from a Delphi background where as throws an exception if it is not the right type.  But the thrust of my question involves them being the desired type.

--
Jason




--
Jason



--
Ralf Bokelberg <[EMAIL PROTECTED]>
Flex & Flash Consultant based in Cologne/Germany __._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to