<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Loop Speed</title>
	<atom:link href="http://jacksondunstan.com/articles/358/feed" rel="self" type="application/rss+xml" />
	<link>http://jacksondunstan.com/articles/358</link>
	<description>Mastering AS3</description>
	<lastBuildDate>Tue, 07 Feb 2012 09:30:08 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/358/comment-page-1#comment-7531</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Fri, 10 Jun 2011 16:38:08 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=358#comment-7531</guid>
		<description>Can&#039;t wait to read that article! :)</description>
		<content:encoded><![CDATA[<p>Can&#8217;t wait to read that article! :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skyboy</title>
		<link>http://jacksondunstan.com/articles/358/comment-page-1#comment-7513</link>
		<dc:creator>skyboy</dc:creator>
		<pubDate>Fri, 10 Jun 2011 02:18:10 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=358#comment-7513</guid>
		<description>I think this is related to my findings of uints being converted to floats in conditionals and brackets (&lt;code&gt;++u; array[u]&lt;/code&gt; faster than &lt;code&gt;array[++u]&lt;/code&gt;). The problem is entirely the compiler, and it&#039;s strange how Adobe has completely missed these problems.
Also, in a further modified operator speed test I&#039;m going to get around to finishing (1000 operations per loop using Apparat to help. Still a lot of manual work) I noticed that the special opcode for inc/dec Number/int are 2x slower than the 3 op code for get/inc/set and at the same time and, when not used in the above areas, boolean operators are O(1) operations on all numeric datatypes and on all mixtures of numeric datatypes.</description>
		<content:encoded><![CDATA[<p>I think this is related to my findings of uints being converted to floats in conditionals and brackets (<code>++u; array[u]</code> faster than <code>array[++u]</code>). The problem is entirely the compiler, and it&#8217;s strange how Adobe has completely missed these problems.<br />
Also, in a further modified operator speed test I&#8217;m going to get around to finishing (1000 operations per loop using Apparat to help. Still a lot of manual work) I noticed that the special opcode for inc/dec Number/int are 2x slower than the 3 op code for get/inc/set and at the same time and, when not used in the above areas, boolean operators are O(1) operations on all numeric datatypes and on all mixtures of numeric datatypes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/358/comment-page-1#comment-7393</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Tue, 07 Jun 2011 17:06:12 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=358#comment-7393</guid>
		<description>It may be. I&#039;ll investigate some more of the &lt;code&gt;int&lt;/code&gt;/&lt;code&gt;uint&lt;/code&gt; effects. In the meantime, check out my more general article on &lt;a href=&quot;/articles/1123&quot; rel=&quot;nofollow&quot;&gt;operator speed&lt;/a&gt;. As noted elsewhere, a more focused test on just the &lt;code&gt;&lt;&lt;/code&gt; operator is needed to really see the effects of &lt;code&gt;int&lt;/code&gt;/&lt;code&gt;uint&lt;/code&gt;.

Thanks for the tip!</description>
		<content:encoded><![CDATA[<p>It may be. I&#8217;ll investigate some more of the <code>int</code>/<code>uint</code> effects. In the meantime, check out my more general article on <a href="/articles/1123" rel="nofollow">operator speed</a>. As noted elsewhere, a more focused test on just the <code>&lt;</code> operator is needed to really see the effects of <code>int</code>/<code>uint</code>.</p>
<p>Thanks for the tip!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: erik</title>
		<link>http://jacksondunstan.com/articles/358/comment-page-1#comment-7389</link>
		<dc:creator>erik</dc:creator>
		<pubDate>Tue, 07 Jun 2011 15:40:49 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=358#comment-7389</guid>
		<description>I am curious if these findings from WIN 10,3,181,22 are worth considering? 

uint &lt; uint		153
int &lt; int		105
int &lt; uint		164
uint &lt; int		142
int &lt; (int)uint		111

It suggests to me that when incrementing through an array/vector, casting vector.length to an int, and also counting up with an int is a worthwhile extra step.

&lt;pre lang=&quot;actionscript3&quot;&gt;
public function intUintShowdown( ):void
{
	super( );
	stage.scaleMode = StageScaleMode.NO_SCALE;
	stage.align = StageAlign.TOP_LEFT;

	var logger:TextField = new TextField();
	logger.autoSize = TextFieldAutoSize.LEFT;
	addChild(logger);
	var maxu:uint = 9999 * 5000;
	var maxi:int = 9999 * 5000;

	logger.appendText( &quot;maxu: &quot; + maxu + &quot;, maxi: &quot; + maxi + &quot;\n&quot; );

	var nowTime:Number = getTimer( );
	for (var u:uint = 0; i &lt; maxu; ++i)
	{
	}
	logger.appendText( &quot;uint &lt; uint\t&quot; + (getTimer()-nowTime) + &quot;\n&quot; );

	nowTime = getTimer( );
	for (var i:int = 0; i &lt; maxi; ++i)
	{
	}
	logger.appendText( &quot;int &lt; int\t&quot; + (getTimer()-nowTime) + &quot;\n&quot; );

	nowTime = getTimer( );
	for (var i2:int = 0; i2 &lt; maxu; ++i2)
	{
	}
	logger.appendText( &quot;int &lt; uint\t&quot; + (getTimer()-nowTime) + &quot;\n&quot; );

	nowTime = getTimer( );
	for (var u2:uint = 0; u2 &lt; maxi; ++u2)
	{
	}
	logger.appendText( &quot;uint &lt; int\t&quot; + (getTimer()-nowTime) + &quot;\n&quot; );


	nowTime = getTimer( );
	var cmaxi:int = maxu;
	for (var i3:int = 0; i3 &lt; cmaxi; ++i3)
	{
	}
	logger.appendText( &quot;int &lt; (int)uint\t&quot; + (getTimer()-nowTime) + &quot;\n&quot; );
}
}
}
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I am curious if these findings from WIN 10,3,181,22 are worth considering? </p>
<p>uint &lt; uint		153<br />
int &lt; int		105<br />
int &lt; uint		164<br />
uint &lt; int		142<br />
int &lt; (int)uint		111</p>
<p>It suggests to me that when incrementing through an array/vector, casting vector.length to an int, and also counting up with an int is a worthwhile extra step.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> intUintShowdown<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;">void</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scaleMode</span> = <span style="color: #004993;">StageScaleMode</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NO_SCALE</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span> = <span style="color: #004993;">StageAlign</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TOP_LEFT</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #6699cc; font-weight: bold;">var</span> logger<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    logger<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">autoSize</span> = <span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>logger<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> maxu<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">9999</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">5000</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> maxi<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">9999</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">5000</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    logger<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;maxu: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> maxu <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;, maxi: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> maxi <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    <span style="color: #6699cc; font-weight: bold;">var</span> nowTime<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</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>
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> u<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <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;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> maxu<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: #000000;">&#125;</span>
    logger<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span> <span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span>uint <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">uint</span>\t<span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</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>nowTime<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span>\n<span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    nowTime = <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><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> i <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> maxi<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: #000000;">&#125;</span>
    logger<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span> <span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span>int <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">int</span>\t<span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</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>nowTime<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span>\n<span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    nowTime = <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><span style="color: #6699cc; font-weight: bold;">var</span> i2<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> i2 <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> maxu<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i2<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#125;</span>
    logger<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span> <span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span>int <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">uint</span>\t<span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</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>nowTime<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span>\n<span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
    nowTime = <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><span style="color: #6699cc; font-weight: bold;">var</span> u2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> u2 <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> maxi<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>u2<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#125;</span>
    logger<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span> <span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span>uint <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">int</span>\t<span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</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>nowTime<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span>\n<span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
&nbsp;
    nowTime = <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: #6699cc; font-weight: bold;">var</span> cmaxi<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = maxu<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i3<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> i3 <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> cmaxi<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>i3<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#125;</span>
    logger<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span> <span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span>int <span style="color: #000066; font-weight: bold;">&amp;</span>lt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">int</span><span style="color: #000000;">&#41;</span><span style="color: #004993;">uint</span>\t<span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</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>nowTime<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span>\n<span style="color: #000066; font-weight: bold;">&amp;</span>quot<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/358/comment-page-1#comment-846</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Wed, 22 Sep 2010 17:16:16 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=358#comment-846</guid>
		<description>I opened the test in &lt;a href=&quot;http://www.docsultant.com/nemo440/&quot; rel=&quot;nofollow&quot;&gt;nemo440&lt;/a&gt; and looked at the bytecode the compiler had generated and it definitely hasn&#039;t optimized any of the test out.  Actually, it virtually never optimizes out any of your code. Take this example of both &lt;a href=&quot;http://en.wikipedia.org/wiki/Dead_code&quot; rel=&quot;nofollow&quot;&gt;dead code&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Constant_folding&quot; rel=&quot;nofollow&quot;&gt;constant folding&lt;/a&gt; I just whipped up:

&lt;pre lang=&quot;actionscript3&quot;&gt;
private function foo(): void
{
	10 + 20;
}
&lt;/pre&gt;

Clearly this does nothing, but here&#039;s what the compiler (MXMLC 4.1) generates:

&lt;pre lang=&quot;text&quot;&gt;
  function private::foo():void	/* disp_id 0*/
  {
    // local_count=1 max_scope=1 max_stack=2 code_len=9
    0       getlocal0     	
    1       pushscope     	
    2       pushbyte      	10
    4       pushbyte      	20
    6       add           	
    7       pop           	
    8       returnvoid    	
  }
&lt;/pre&gt;

As you can see, it didn&#039;t do either optimization.

Still, your results actually don&#039;t differ from mine in the first place, at least if we compensate for CPU speed. Your &lt;code&gt;for&lt;/code&gt; loop time is 2.42x slower than your &lt;code&gt;for-each&lt;/code&gt; time. If you refer to my Flash Player 10.1 &lt;a href=&quot;/articles/718&quot; rel=&quot;nofollow&quot;&gt;performance update&lt;/a&gt; of this article, you&#039;ll see that my &lt;code&gt;for&lt;/code&gt; loop time is 2.44x slower than my &lt;code&gt;for-each&lt;/code&gt; time.</description>
		<content:encoded><![CDATA[<p>I opened the test in <a href="http://www.docsultant.com/nemo440/" rel="nofollow">nemo440</a> and looked at the bytecode the compiler had generated and it definitely hasn&#8217;t optimized any of the test out.  Actually, it virtually never optimizes out any of your code. Take this example of both <a href="http://en.wikipedia.org/wiki/Dead_code" rel="nofollow">dead code</a> and <a href="http://en.wikipedia.org/wiki/Constant_folding" rel="nofollow">constant folding</a> I just whipped up:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> foo<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;">void</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #000000; font-weight:bold;">10</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Clearly this does nothing, but here&#8217;s what the compiler (MXMLC 4.1) generates:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">  function private::foo():void    /* disp_id 0*/
  {
    // local_count=1 max_scope=1 max_stack=2 code_len=9
    0       getlocal0         
    1       pushscope         
    2       pushbyte          10
    4       pushbyte          20
    6       add               
    7       pop               
    8       returnvoid        
  }</pre></div></div>

<p>As you can see, it didn&#8217;t do either optimization.</p>
<p>Still, your results actually don&#8217;t differ from mine in the first place, at least if we compensate for CPU speed. Your <code>for</code> loop time is 2.42x slower than your <code>for-each</code> time. If you refer to my Flash Player 10.1 <a href="/articles/718" rel="nofollow">performance update</a> of this article, you&#8217;ll see that my <code>for</code> loop time is 2.44x slower than my <code>for-each</code> time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/358/comment-page-1#comment-845</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Wed, 22 Sep 2010 16:57:01 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=358#comment-845</guid>
		<description>I&#039;ve actually got a two-part series of articles that covers this: &lt;a href=&quot;/articles/649&quot; rel=&quot;nofollow&quot;&gt;Array vs. Vector&lt;/a&gt;. In there I explicitly test with different types of elements: &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;uint&lt;/code&gt;, &lt;code&gt;Number&lt;/code&gt;, &lt;code&gt;Boolean&lt;/code&gt;, and &lt;code&gt;String&lt;/code&gt;. Check it out for the full performance differences as well as the &lt;a href=&quot;/articles/774&quot; rel=&quot;nofollow&quot;&gt;followup article&lt;/a&gt; testing performance with Flash Player 10.1.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve actually got a two-part series of articles that covers this: <a href="/articles/649" rel="nofollow">Array vs. Vector</a>. In there I explicitly test with different types of elements: <code>int</code>, <code>uint</code>, <code>Number</code>, <code>Boolean</code>, and <code>String</code>. Check it out for the full performance differences as well as the <a href="/articles/774" rel="nofollow">followup article</a> testing performance with Flash Player 10.1.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jardilio</title>
		<link>http://jacksondunstan.com/articles/358/comment-page-1#comment-843</link>
		<dc:creator>jardilio</dc:creator>
		<pubDate>Wed, 22 Sep 2010 15:50:27 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=358#comment-843</guid>
		<description>A friend just referred me to this page and I think that the test scenario in play here is getting optimized by the compiler as you are not really doing anything with the values in the array for the for loop case. I condensed your test to just working with the for and for each for an array and the only thing I modified was change &quot;a = ?&quot; to &quot;a += ?&quot;. I ended up getting very different results where the foreach was actually much faster. I think what was happening in your test case was that the value from the array was not actually getting retrieved in the for loop as it was getting optimized by the compiler.
&lt;pre lang=&quot;actionscript3&quot;&gt;
const SIZE:uint = 6000;
const REPS:uint = 2000;

var i:int;
var s:String;
var a:int = 0;
var b:String;
var rep:int;
var res:String = &quot;For-each times:\n&quot;;
var before:uint;
var after:uint;
var arr:Array = new Array(SIZE);

for (i = 0; i &lt; SIZE; ++i)
{
	arr[i] = int(Math.random()*1000);
}

before = getTimer();
for (rep = 0; rep &lt; REPS; ++rep)
{
	for each (i in arr)
	{
		a += i;
	}
}
after = getTimer();
res += &quot;\tArray: &quot; + (after-before) + &quot;\n&quot;;

res += &quot;For times:\n&quot;;

a = 0;

before = getTimer();
for (rep = 0; rep &lt; REPS; ++rep)
{
	for (i = 0; i &lt; SIZE; ++i)
	{
		a += arr[i];
	}
}
after = getTimer();
res += &quot;\tArray: &quot; + (after-before) + &quot;\n&quot;;

trace(res);
&lt;/pre&gt;

&lt;pre lang=&quot;text&quot;&gt;
For-each times:
	Array: 2603
For times:
	Array: 6313
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>A friend just referred me to this page and I think that the test scenario in play here is getting optimized by the compiler as you are not really doing anything with the values in the array for the for loop case. I condensed your test to just working with the for and for each for an array and the only thing I modified was change &#8220;a = ?&#8221; to &#8220;a += ?&#8221;. I ended up getting very different results where the foreach was actually much faster. I think what was happening in your test case was that the value from the array was not actually getting retrieved in the for loop as it was getting optimized by the compiler.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">const SIZE<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">6000</span><span style="color: #000066; font-weight: bold;">;</span>
const REPS<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">2000</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<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: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> s<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> a<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> <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> rep<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> res<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;For-each times:<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> before<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> after<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #6699cc; font-weight: bold;">var</span> arr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Array</span><span style="color: #000000;">&#40;</span>SIZE<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<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> SIZE<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>
    arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> = <span style="color: #004993;">int</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</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; font-weight:bold;">1000</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
before = <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>rep = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> rep <span style="color: #000066; font-weight: bold;">&lt;</span> REPS<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>rep<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span>i <span style="color: #0033ff; font-weight: bold;">in</span> arr<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        a <span style="color: #000066; font-weight: bold;">+</span>= i<span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
after = <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>
res <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;<span style="">\t</span>Array: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>after<span style="color: #000066; font-weight: bold;">-</span>before<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
res <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;For times:<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
a = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
before = <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>rep = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> rep <span style="color: #000066; font-weight: bold;">&lt;</span> REPS<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>rep<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</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> SIZE<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>
        a <span style="color: #000066; font-weight: bold;">+</span>= arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
after = <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>
res <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;<span style="">\t</span>Array: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000;">&#40;</span>after<span style="color: #000066; font-weight: bold;">-</span>before<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>res<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">For-each times:
    Array: 2603
For times:
    Array: 6313</pre></div></div>

]]></content:encoded>
	</item>
	<item>
		<title>By: jwopitz</title>
		<link>http://jacksondunstan.com/articles/358/comment-page-1#comment-842</link>
		<dc:creator>jwopitz</dc:creator>
		<pubDate>Wed, 22 Sep 2010 15:39:54 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=358#comment-842</guid>
		<description>Sorry the Vector type brackets didn&#039;t show.  I meant:

Vector (ComplexObject)

vs 

Vector (int or String or other simple types)</description>
		<content:encoded><![CDATA[<p>Sorry the Vector type brackets didn&#8217;t show.  I meant:</p>
<p>Vector (ComplexObject)</p>
<p>vs </p>
<p>Vector (int or String or other simple types)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jwopitz</title>
		<link>http://jacksondunstan.com/articles/358/comment-page-1#comment-841</link>
		<dc:creator>jwopitz</dc:creator>
		<pubDate>Wed, 22 Sep 2010 15:38:07 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=358#comment-841</guid>
		<description>Have you found any performance drop when using complex object types for the Vectors.  I can&#039;t remember where I heard this but accessing the following:

for.. Vector

is much slower than 

for.. Vector</description>
		<content:encoded><![CDATA[<p>Have you found any performance drop when using complex object types for the Vectors.  I can&#8217;t remember where I heard this but accessing the following:</p>
<p>for.. Vector</p>
<p>is much slower than </p>
<p>for.. Vector</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Li</title>
		<link>http://jacksondunstan.com/articles/358/comment-page-1#comment-248</link>
		<dc:creator>Li</dc:creator>
		<pubDate>Fri, 09 Oct 2009 00:18:28 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=358#comment-248</guid>
		<description>Excellent test. I&#039;ve seen similar ones but this is so clear and effective. Thanks!</description>
		<content:encoded><![CDATA[<p>Excellent test. I&#8217;ve seen similar ones but this is so clear and effective. Thanks!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

