<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>simonrichardson.info &#187; performance</title> <atom:link href="http://www.simonrichardson.info/category/performance/feed/" rel="self" type="application/rss+xml" /><link>http://www.simonrichardson.info</link> <description>ActionScript &#38; Android</description> <lastBuildDate>Mon, 05 Dec 2011 09:54:05 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.2.1</generator> <item><title>Missed opportunity</title><link>http://www.simonrichardson.info/2011/08/05/missed-opportunity/</link> <comments>http://www.simonrichardson.info/2011/08/05/missed-opportunity/#comments</comments> <pubDate>Fri, 05 Aug 2011 10:42:45 +0000</pubDate> <dc:creator>Simon Richardson</dc:creator> <category><![CDATA[ActionScript]]></category> <category><![CDATA[ActionScript3]]></category> <category><![CDATA[Compiler]]></category> <category><![CDATA[performance]]></category> <guid
isPermaLink="false">http://www.simonrichardson.info/?p=201</guid> <description><![CDATA[Again I&#8217;m talking about Adobe and another missed opportunity in regards to the AVM/ActionScript3 stack. The following is a criticism of the company and not thinking about the broader horizons, not really anticipating what developers want. It&#8217;s only now that I believe they&#8217;re beginning to understanding this, but I think it&#8217;s a little too late, [...]]]></description> <content:encoded><![CDATA[<p>Again I&#8217;m talking about Adobe and another missed opportunity in regards to the AVM/ActionScript3 stack. The following is a criticism of the company and not thinking about the broader horizons, not really anticipating what developers want. It&#8217;s only now that I believe they&#8217;re beginning to understanding this, but I think it&#8217;s a little too late, the ship has sailed! Developers are what push the technology, look at all the 3D engines created 3-4 years back with massive push of client projects and money for developers. It&#8217;s only now that real 3D was implemented!</p><p>Look how Javascript/CSS3 has moved to the forefront, developers are implementing what flash could do a few years back, but are improving it with semantics and readability. Taking on some of the frailties of Flash (screen readability, fallbacks and other browser implementation issues), don&#8217;t get me wrong, it&#8217;s still not perfect, but it&#8217;s better than some of Flash&#8217;s attempts.</p><p>I know that there is only a limited amount of resources to implement some of the things developers want, but it seems that they&#8217;re not thinking about the broader picture. The company has spent quite a long time implementing the iOS packaging tool for Flash for example. It&#8217;s a great little tool, but probably underused considering it&#8217;s possible potential. Why do I talk about this, well it turns out that the way the packaging tool works is that it provides away to compile your ActionScript3 code via the <a
href="http://llvm.org/">LLVM</a> into AVM code. It now turns from a JIT compiled language to AOT compiled language with some issues currently that you can&#8217;t have multiple swfs with code in them. This missed opportunity here is that LLVM can have many backend outputs, Adobe only implemented/used one backend and that&#8217;s targeting ARM (for iOS). It would be that much of a stretch of imagination to implement a different backend, C/C++/Java (the list continues). So instead of seeing ActionScript as a dead end language with no possible road a head long term (unlike <a
href="http://haxe.org">haXe</a>) there could have been a possibility where your ActionScript code could run natively on any platform with the speed of C/C++ (hand written code would obviously be much faster that this version, but it would be faster than running on the AVM!).</p><p>Imagine the possibilities, super fast code with the ease of developing with ActionScript&#8230; shame it&#8217;s never going to happen!</p> ]]></content:encoded> <wfw:commentRss>http://www.simonrichardson.info/2011/08/05/missed-opportunity/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>AS3-DOM Example</title><link>http://www.simonrichardson.info/2011/06/03/as3-dom-example/</link> <comments>http://www.simonrichardson.info/2011/06/03/as3-dom-example/#comments</comments> <pubDate>Fri, 03 Jun 2011 17:02:29 +0000</pubDate> <dc:creator>Simon Richardson</dc:creator> <category><![CDATA[ActionScript]]></category> <category><![CDATA[ActionScript3]]></category> <category><![CDATA[performance]]></category> <guid
isPermaLink="false">http://www.simonrichardson.info/?p=151</guid> <description><![CDATA[Today I managed to get some free time at lunch to implement a very quick example of what is possible with AS3-DOM. There isn&#8217;t much really to it, all it does is sort through a series of Layers (DOMNodes) and then animate them to a new position. It&#8217;s amazingly quick for a first example and [...]]]></description> <content:encoded><![CDATA[<p>Today I managed to get some free time at lunch to implement a very quick <a
href="https://github.com/stickupkid/as3-dom-examples/tree/master/examples/filter-example/org/flash/dom/examples/filter">example</a> of what is possible with AS3-DOM. There isn&#8217;t much really to it, all it does is sort through a series of <a
href="https://github.com/stickupkid/as3-dom-examples/blob/master/examples/filter-example/org/flash/dom/examples/filter/elements/Layer.as">Layers</a> (<a
href="https://github.com/stickupkid/as3-dom/blob/master/src/org/osflash/dom/element/DOMNode.as">DOMNodes</a>) and then animate them to a new position. It&#8217;s amazingly quick for a first example and I was more than impressed with the results! As this is release 0.0.1 alpha there is a lot to improve, especially the need to create an object pool for the expressions. Maybe I&#8217;ll get some free time next week to implement this&#8230;</p> <object
classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="FilterExample" width="580" height="580" name="FilterExample"><param
name="movie" value="http://www.simonrichardson.info/wp-content/uploads/2011/06/FilterExample.swf" /><param
name="name" value="FilterExample" /> <!--[if !IE]>--> <object
type="application/x-shockwave-flash" data="http://www.simonrichardson.info/wp-content/uploads/2011/06/FilterExample.swf" width="580" height="580" name="FilterExample"> <!--<![endif]--> <!--[if !IE]>--> </object> <!--<![endif]--> </object><p> View the <a
href="https://github.com/stickupkid/as3-dom-examples/tree/master/examples/filter-example/org/flash/dom/examples/filter">source code</a></p> ]]></content:encoded> <wfw:commentRss>http://www.simonrichardson.info/2011/06/03/as3-dom-example/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>AS3-Mixins update &amp; AS3-DOM introduction</title><link>http://www.simonrichardson.info/2011/05/26/as3-mixins-update-as3-dom-introduction/</link> <comments>http://www.simonrichardson.info/2011/05/26/as3-mixins-update-as3-dom-introduction/#comments</comments> <pubDate>Thu, 26 May 2011 17:31:47 +0000</pubDate> <dc:creator>Simon Richardson</dc:creator> <category><![CDATA[ActionScript]]></category> <category><![CDATA[ActionScript3]]></category> <category><![CDATA[performance]]></category> <guid
isPermaLink="false">http://www.simonrichardson.info/?p=138</guid> <description><![CDATA[This is just a really quick update on a couple of projects I&#8217;ve got going: AS3-Mixins I&#8217;ve been fortunate to have some free time recently (no idea how or where from!), but I&#8217;ve managed to get AS3-Mixins to a stable enough state so that it can be used without it break everywhere. There are a [...]]]></description> <content:encoded><![CDATA[<p>This is just a really quick update on a couple of projects I&#8217;ve got going:</p><p><strong>AS3-Mixins</strong><br
/> I&#8217;ve been fortunate to have some free time recently (no idea how or where from!), but I&#8217;ve managed to get AS3-Mixins to a stable enough state so that it can be used without it break everywhere. There are a few notable improvements over the first initial creation of the project. It&#8217;s gone through a massive re-factor, with the aim to improve the speed of mixin creation at startup. Most of the work has also been looking into improving memory consumption and I spent a lot of time caching bytecode and types from flemit and the mixins project. There is still a bit to do in this area, but it&#8217;s a lot more efficient that it&#8217;s ever been.</p><p>I&#8217;ve also added the ability for method overloading from a super class, added the ability to use a mixin in a MixinFactoryPool and tons more. This was mainly aimed at the creation of say tiles in a game, so at the start of a level you can create a series of titles/enemies/etc and reuse them without worrying about how to store them or reuse them. It&#8217;s a strongly type factory so it knows what mixin belongs to which pools. There is even a debug helper class which you can use to find out how healthy the MixinFactoryPools are i.e. you can monitor how full the pools are and when they&#8217;re about to be grow because the pools will be exhausted. All very useful for development.</p><p><strong>AS3-DOM</strong><br
/> Another project I&#8217;ve started (told you I&#8217;ve got some spare time!) is the creation of a DOM system in AS3. With the aim to provide a very easy selection tool for user interfaces (or anything else you can thing of using it with). It&#8217;s basically in it&#8217;s infancy, but it&#8217;s going to be something like xpath for AS3. It&#8217;s not going to be the same as xpath, as I&#8217;ve not got the time nor the inclination to write every single xpath rule and it would take far too long and I&#8217;m sure you could get paid for doing that! One added bonus is that the xpath selection can actually work on the DisplayObject list. The down side is you have to convert the DisplayObject list to the DOM. I may look at away to make a better adapter for this, but for now a help function should suffice.</p><p>You can view all of this at my <a
href="https://github.com/stickupkid">github repo</a></p> ]]></content:encoded> <wfw:commentRss>http://www.simonrichardson.info/2011/05/26/as3-mixins-update-as3-dom-introduction/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>SingleSignal</title><link>http://www.simonrichardson.info/2011/03/31/singlesignal/</link> <comments>http://www.simonrichardson.info/2011/03/31/singlesignal/#comments</comments> <pubDate>Thu, 31 Mar 2011 11:05:02 +0000</pubDate> <dc:creator>Simon Richardson</dc:creator> <category><![CDATA[ActionScript]]></category> <category><![CDATA[ActionScript3]]></category> <category><![CDATA[performance]]></category> <guid
isPermaLink="false">http://www.simonrichardson.info/?p=114</guid> <description><![CDATA[Recently we&#8217;ve been working on a project for a limited device and have been concentrating on the performance aspects of the application. We use signals quite extensively in the project application (to good effect!), but it does intrigue me when you come to any stage of application development, that there are certain things you know [...]]]></description> <content:encoded><![CDATA[<p>Recently <a
href="http://www.ustwo.co.uk">we&#8217;ve</a> been working on a project for a limited device and have been concentrating on the performance aspects of the application. We use signals quite extensively in the project application (to good effect!), but it does intrigue me when you come to any stage of application development, that there are certain things you know about the application and what it does and when. When looking at Signals specifically these things are:</p><ol><li>You know when something needs to listen to a Signal</li><li>You should know how many times your registering to said Signal</li></ol><p>I&#8217;m more interested in number 2 for now. As the application is ironed out over time, it makes me wonder why we&#8217;ve got this extra functionality of allowing multiple listeners to registered to a Signal, when only one suffices. I&#8217;ve never been a fan of hooking on to direct callbacks, mainly for the reason that you don&#8217;t know what is coming through as the arguments and the added bonus of reading the documentation every time. I&#8217;m more interested in self documenting code, not that I&#8217;m against documentation! I just want to be able at a glance to understand what the code does (where possible of course).</p><p>I had thought about implementing a SingleSignal. The whole purpose of this is to provide away to have a one listener at a time callback. The SingleSignal had to satisfy the following:</p><ol><li>Only register one listener at a time</li><li>Notify the developer if they tried to register more than one listener</li><li>Be faster than the default Signal, as we&#8217;ve not got the over head of the linked list and Dictionary</li><li>Use less memory than the default Signal</li></ol><p>It didn&#8217;t take me long to implement the functionality of the SingleSignal, as I already had the excellent work of Robert Penner and Joa Ebert to start from. The current implementation is in my <a
href="https://github.com/stickupkid/as3-signals/blob/master/src/org/osflash/signals/SingleSignal.as">github repo</a>. I&#8217;ve also created some unit tests to help improve the robustness and prevent errors slipping through.</p><p>The last thing I did was verify the performance using the existing <a
href="https://github.com/robertpenner/as3-signals/tree/master/performance-test/org/osflash/signals">performance testing in the repo</a>. Here are the results from a release Flash Player (10.1r85.3) on a mac running 10.6.2:</p><p><strong>AddOncePerformance</strong><br
/> Note: All tests min time was 0ms for all.<TABLE><TR><TH></TH><TH>DeluxeSignal</TH><TH>Signal</TH><TH>SingleSignal</TH></TR><TR><TD>Frames per second (fps):</TD><TD>49fps</TD><TD>60fps</TD><TD>60fps</TD></TR><TR><TD>Memory used:</TD><TD>6mb</TD><TD>6mb</TD><TD>4mb</TD></TR><TR><TD>Max time:</TD><TD>8ms</TD><TD>7ms</TD><TD>4ms</TD></TR></TABLE></p><p><strong>RemovePerformance</strong><br
/> Note: All tests ran at 60fps and the min time was 0ms for all.<TABLE><TR><TH></TH><TH>DeluxeSignal</TH><TH>Signal</TH><TH>SingleSignal</TH></TR><TR><TD>Memory used:</TD><TD>6mb</TD><TD>6mb</TD><TD>4mb</TD></TR><TR><TD>Max time:</TD><TD>6ms</TD><TD>6ms</TD><TD>4ms</TD></TR></TABLE></p><p>There you have it. It&#8217;s up to 33% faster, which won&#8217;t be that noticiable, depends on how many addOnce or add and dispatches you&#8217;re doing. It also uses 2mb less, which is a good improvement overall. So if you know what the restrictions are of your application and you know you&#8217;re going to add one listener and you want to use less memory then a SingleSignal might be for you&#8230;</p><p><strong>EDIT:</strong> slight refractor to make the article more concise.</p> ]]></content:encoded> <wfw:commentRss>http://www.simonrichardson.info/2011/03/31/singlesignal/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Interruption</title><link>http://www.simonrichardson.info/2010/05/06/interruption/</link> <comments>http://www.simonrichardson.info/2010/05/06/interruption/#comments</comments> <pubDate>Thu, 06 May 2010 15:59:55 +0000</pubDate> <dc:creator>Simon Richardson</dc:creator> <category><![CDATA[ActionScript]]></category> <category><![CDATA[ActionScript3]]></category> <category><![CDATA[HaXe]]></category> <category><![CDATA[HaXe-C++]]></category> <category><![CDATA[performance]]></category> <guid
isPermaLink="false">http://www.simonrichardson.info/?p=51</guid> <description><![CDATA[I know I&#8217;ve supposed to have written about Unit testing (part 3), it&#8217;s in draft and needs amending, but in the mean time I&#8217;ve been thinking about compilers and languages. I&#8217;ve been reading the dragon book of late, because I&#8217;ve needed to implement a coding style verifier and micro optimiser (something which has been talked [...]]]></description> <content:encoded><![CDATA[<p>I know I&#8217;ve supposed to have written about Unit testing (part 3), it&#8217;s in draft and needs amending, but in the mean time I&#8217;ve been thinking about compilers and languages. I&#8217;ve been reading the <a
href="http://en.wikipedia.org/wiki/Dragon_Book_(computer_science)">dragon book</a> of late, because I&#8217;ve needed to implement a coding style verifier and micro optimiser (something which has been talked about in length by developers).</p><p>One thing has struck me of late and that is; we do have really fast operational codes in the <a
href="http://www.ncannasse.fr/blog/adobe_alchemy">language</a>, but other than <a
href="http://haxe.org/">haXe</a> and <a
href="http://labs.adobe.com/technologies/alchemy/">Adobe Alchemy</a> not much is taking advantage of it. You can of course try and use <a
href="http://blog.joa-ebert.com/2009/08/05/turbodieselsportinjection/">TDSI</a> from <a
href="http://blog.joa-ebert.com/">Joa Ebert</a>, but why should we have to optimise something after we&#8217;ve written it? This should be either standard from the language or the compiler.</p><p><strong>So what is this really about?</strong><br
/> This is about wanting to code without thinking about optimising the basics, you don&#8217;t hear of C/C++/C#/Java developers talking about trying to squeeze every ounce of power from the language every time they code something. I&#8217;m not saying you shouldn&#8217;t optimise, what I am saying is that as a platform it always seems like we&#8217;re starting with a handicap.<br
/> I want the fasting language for the platform and have all the features for the language. I really like method overloading from Java. I know the AVM2 doesn&#8217;t support it by default, but that doesn&#8217;t stop you from implementing in some way. A perfect example of this is type parameters (generics) of the Vector class, which I really like from Java and HaXe, but why is it not default on all objects. The compiler checks what your implementing and the aligns it to correct compound types.</p><p>Now why can&#8217;t a language do this for method overloading, by simply changing the method signature to something else at compile time.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td
class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">method</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">method</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> age<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #004993;">method</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'fred'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #004993;">method</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'jim'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">24</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div><p>This would be translated to the following:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td
class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #339966; font-weight: bold;">function</span> method_StringVoid<span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #339966; font-weight: bold;">function</span> method_StringIntVoid<span style="color: #000000;">&#40;</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> age<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #000000;">&#125;</span>
method_StringVoid<span style="color: #000000;">&#40;</span><span style="color: #990000;">'fred'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
method_StringIntVoid<span style="color: #000000;">&#40;</span><span style="color: #990000;">'jim'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">24</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div><p>The reason for the curious method signature is to enable something to call the method if it&#8217;s not directly know i.e. external swf file etc.</p><p>Also why is the fastest int, not used automatically? To use the fastest int, you have to delve into opcodes, which seems extraordinary as you&#8217;re actually saying to your developers &#8220;we do have this really fast player, but you&#8217;re not allowed to use it&#8221;. It would be great if a language just used the fastest int and not require the developer to jump into another language (C/C++/haXe).</p> ]]></content:encoded> <wfw:commentRss>http://www.simonrichardson.info/2010/05/06/interruption/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Casting Performance</title><link>http://www.simonrichardson.info/2010/03/11/casting-performance/</link> <comments>http://www.simonrichardson.info/2010/03/11/casting-performance/#comments</comments> <pubDate>Thu, 11 Mar 2010 21:08:19 +0000</pubDate> <dc:creator>Simon Richardson</dc:creator> <category><![CDATA[ActionScript3]]></category> <category><![CDATA[performance]]></category> <category><![CDATA[flash]]></category> <guid
isPermaLink="false">http://www.simonrichardson.info/?p=12</guid> <description><![CDATA[I was reading a couple of blog posts about performance recently with trying to bring some speed to my personal project, more about that in up and coming posts. One interesting fact that keeps rearing it&#8217;s head is that we should never cast[wiki], when coding. I find this statement a little hard to stomach. I&#8217;ve [...]]]></description> <content:encoded><![CDATA[<p>I was reading a couple of blog posts about performance recently with trying to bring some speed to my personal project, more about that in up and coming posts. One interesting fact that keeps rearing it&#8217;s head is that we should never cast[wiki], when coding. I find this statement a little hard to stomach. I&#8217;ve been writing OOP for some years and find it hard to not cast! I try and reduce the amount of casting required by making sure I&#8217;m explicit as much as possible, but even so, you have to do it (unless some one can show me how to write a very complex project without it!).</p><p>So now we know we have to do it, what are the best ways to do it. I was running some tests last night and I was actually surprised that I didn&#8217;t know this, because it&#8217;s obvious.</p><p>I made a test which just loops through a for loop attempting to cast various items or the iterator. It&#8217;s fairly explanatory, just run the for loops multiple times until you get a big enough delta between beforeTime and the current time to make any sense.</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
</pre></td><td
class="code"><pre class="actionscript3" style="font-family:monospace;">const NUM_ITERATIONS <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">1000000</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> i <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> beforeTime <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> element <span style="color: #000066; font-weight: bold;">:</span> IElement = ElementFactory<span style="color: #000066; font-weight: bold;">.</span>create<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
beforeTime = <span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>= NUM_ITERATIONS<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> item0 <span style="color: #000066; font-weight: bold;">:</span> Element = Element<span style="color: #000000;">&#40;</span>element<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;<span style="">\t</span>Cast method (Class(instance)): &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>beforeTime<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
beforeTime = <span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>= NUM_ITERATIONS<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> item1 <span style="color: #000066; font-weight: bold;">:</span> Element = element <span style="color: #0033ff; font-weight: bold;">as</span> Element<span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;<span style="">\t</span>Cast method (instance as Class): &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>beforeTime<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
beforeTime = <span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>= NUM_ITERATIONS<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> item2 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;<span style="">\t</span>Cast method (int(instance)): &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>beforeTime<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
beforeTime = <span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>= NUM_ITERATIONS<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> item3 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">int</span> = i <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;<span style="">\t</span>Cast method (instance as int): &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>beforeTime<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
beforeTime = <span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>= NUM_ITERATIONS<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> item4 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #004993;">String</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;<span style="">\t</span>Cast method (String(instance)): &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>beforeTime<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
beforeTime = <span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>= NUM_ITERATIONS<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> item5 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = i <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;<span style="">\t</span>Cast method (instance as String): &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>beforeTime<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
beforeTime = <span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span>i=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span>= NUM_ITERATIONS<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> item6 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = i<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;<span style="">\t</span>Cast method (instance.toString()): &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">getTimer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">-</span>beforeTime<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></td></tr></table></div><p><strong>So the results:</strong></p><p>Cast method (Class(instance)): 6<br
/> Cast method (instance as Class): 75<br
/> Cast method (int(instance)): 3<br
/> Cast method (instance as int): 61<br
/> Cast method (String(instance)): 407<br
/> Cast method (instance as String): 67<br
/> Cast method (instance.toString()): 478</p><p><strong>So what does this mean?</strong></p><p>To keep it short. Don&#8217;t cast to another type, so don&#8217;t go from int to String, use &#8216;as&#8217;. Don&#8217;t use the toString() method for casting a int to a string, it&#8217;s very costly.</p><p>This is the important bit: Only if you know what the instance is it safe to do a cast and make sure you don&#8217;t use &#8216;as&#8217;. So if you know it&#8217;s an Element because of the IElement interface or because of a way to quickly test it (enum class which you define), then use type conversion.</p><p>Casting is expensive if you do it wrong, so make sure you do it correctly.</p><p><strong>Note:</strong><br
/> I tested this with the latest Flash Player 10.1 b3, so this could all change. I&#8217;ve not tested with old Flash Players because I&#8217;ve got better things to do! Also test with the normal release and not the debugger, I can not emphasis that enough!</p><p><strong>Update:</strong><br
/> This (i as String) would equal null, I should of checked this.</p> ]]></content:encoded> <wfw:commentRss>http://www.simonrichardson.info/2010/03/11/casting-performance/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
