<?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: XOR Swap</title>
	<atom:link href="http://jacksondunstan.com/articles/318/feed" rel="self" type="application/rss+xml" />
	<link>http://jacksondunstan.com/articles/318</link>
	<description>Mastering AS3</description>
	<lastBuildDate>Mon, 14 May 2012 17:02:12 +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/318/comment-page-1#comment-1022</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Sat, 23 Oct 2010 00:21:09 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=318#comment-1022</guid>
		<description>I always use the latest release player. At the time, that was Flash Player 10.0. Since I never test on a debug player, I didn&#039;t know that XOR is faster there. Thanks for the explanation.</description>
		<content:encoded><![CDATA[<p>I always use the latest release player. At the time, that was Flash Player 10.0. Since I never test on a debug player, I didn&#8217;t know that XOR is faster there. Thanks for the explanation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skyboy</title>
		<link>http://jacksondunstan.com/articles/318/comment-page-1#comment-1020</link>
		<dc:creator>skyboy</dc:creator>
		<pubDate>Fri, 22 Oct 2010 23:58:01 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=318#comment-1020</guid>
		<description>Were you using an old version of the debug player? Those results look far too far apart, but in both tests XOR swap is faster in the debug player, which is probably where the people who use it got idea that three XOR and three assignments is faster than only three assignments.</description>
		<content:encoded><![CDATA[<p>Were you using an old version of the debug player? Those results look far too far apart, but in both tests XOR swap is faster in the debug player, which is probably where the people who use it got idea that three XOR and three assignments is faster than only three assignments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bob</title>
		<link>http://jacksondunstan.com/articles/318/comment-page-1#comment-54</link>
		<dc:creator>Bob</dc:creator>
		<pubDate>Tue, 22 Sep 2009 22:00:04 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=318#comment-54</guid>
		<description>There are some situations where the XOR swap is handy albeit not necessarily in actionscript.  One particularly useful situation is in embedded systems where you do not have any room on the stack or heap to allocate a swap variable, so you are forced to do things the hard way.

On some architecture, xor swap is a lot faster than a temp var, but this is usually truer in the lower level systems (assembler etc).</description>
		<content:encoded><![CDATA[<p>There are some situations where the XOR swap is handy albeit not necessarily in actionscript.  One particularly useful situation is in embedded systems where you do not have any room on the stack or heap to allocate a swap variable, so you are forced to do things the hard way.</p>
<p>On some architecture, xor swap is a lot faster than a temp var, but this is usually truer in the lower level systems (assembler etc).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/318/comment-page-1#comment-53</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Tue, 22 Sep 2009 16:36:49 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=318#comment-53</guid>
		<description>Wow, those are some really surprising results! To test, I tried it out in the standalone players on the same Windows box as in the article and got this:

&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;Player&lt;/th&gt;
&lt;th&gt;Assign Swap Time&lt;/th&gt;
&lt;th&gt;Assign Swap Time (instancing)&lt;/th&gt;
&lt;th&gt;XOR Swap Time&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Release&lt;/td&gt;
&lt;td&gt;237&lt;/td&gt;
&lt;td&gt;269&lt;/td&gt;
&lt;td&gt;280&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;Debug&lt;/td&gt;
&lt;td&gt;11308&lt;/td&gt;
&lt;td&gt;11350&lt;/td&gt;
&lt;td&gt;11141&lt;/td&gt;
&lt;/table&gt;

Those debug times look kind of crazy to me, but they are repeatable. The release times are pretty close to what I get with the browser plugin though. I wonder what accounts for our difference, especially since we have such similar machines.

Thanks for your comment and your result times.</description>
		<content:encoded><![CDATA[<p>Wow, those are some really surprising results! To test, I tried it out in the standalone players on the same Windows box as in the article and got this:</p>
<table>
<tr>
<th>Player</th>
<th>Assign Swap Time</th>
<th>Assign Swap Time (instancing)</th>
<th>XOR Swap Time</th>
</tr>
<tr>
<td>Release</td>
<td>237</td>
<td>269</td>
<td>280</td>
</tr>
<tr>
<td>Debug</td>
<td>11308</td>
<td>11350</td>
<td>11141</td>
</tr>
</table>
<p>Those debug times look kind of crazy to me, but they are repeatable. The release times are pretty close to what I get with the browser plugin though. I wonder what accounts for our difference, especially since we have such similar machines.</p>
<p>Thanks for your comment and your result times.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: grapefrukt</title>
		<link>http://jacksondunstan.com/articles/318/comment-page-1#comment-52</link>
		<dc:creator>grapefrukt</dc:creator>
		<pubDate>Tue, 22 Sep 2009 08:28:19 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=318#comment-52</guid>
		<description>Strangely I get these times in the standalone (release) player:
Assign swap (including instancing) time: 414
Assign swap time: 320
XOR swap time: 357

What really surprised me, even though I knew that the debug player is a bit slower, is that if i run it there (still the code compiled in release) I get these results:
Assign swap (including instancing) time: 890
Assign swap time: 790
XOR swap time: 625

That&#039;s almost twice the execution time. I really need to set up my dev enviroment to launch both the debug and standalone players. 

All this was run on my 2.2 Ghz Intel Core 2 Duo with 3.5GB RAM running Windows XP SP3</description>
		<content:encoded><![CDATA[<p>Strangely I get these times in the standalone (release) player:<br />
Assign swap (including instancing) time: 414<br />
Assign swap time: 320<br />
XOR swap time: 357</p>
<p>What really surprised me, even though I knew that the debug player is a bit slower, is that if i run it there (still the code compiled in release) I get these results:<br />
Assign swap (including instancing) time: 890<br />
Assign swap time: 790<br />
XOR swap time: 625</p>
<p>That&#8217;s almost twice the execution time. I really need to set up my dev enviroment to launch both the debug and standalone players. </p>
<p>All this was run on my 2.2 Ghz Intel Core 2 Duo with 3.5GB RAM running Windows XP SP3</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jackson</title>
		<link>http://jacksondunstan.com/articles/318/comment-page-1#comment-51</link>
		<dc:creator>jackson</dc:creator>
		<pubDate>Mon, 21 Sep 2009 16:28:58 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=318#comment-51</guid>
		<description>Good point. My reason for leaving out that case was to make sure I was testing just the swap algorithm and not the variable instantiation. But since you expressed interest and I never did the test, I figured I might as well:

&lt;pre lang=&quot;actionscript3&quot;&gt;
beforeTime = getTimer();
for (i = 0; i &lt; SWAP_REPS; ++i)
{
    var temp2:int = a;
    a = b;
    b = temp;
}
logger.appendText(&quot;Assign swap time (new temp): &quot; + (getTimer()-beforeTime) + &quot;\n&quot;);
&lt;/pre&gt;

On the same Windows machine, I&#039;m getting nearly identical times to the other version with a temporary variable. I&#039;ve run it a couple dozen times and the difference is +/- 2 ms.

Thanks for the suggestion!</description>
		<content:encoded><![CDATA[<p>Good point. My reason for leaving out that case was to make sure I was testing just the swap algorithm and not the variable instantiation. But since you expressed interest and I never did the test, I figured I might as well:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">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> SWAP_REPS<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> temp2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = a<span style="color: #000066; font-weight: bold;">;</span>
    a = <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #004993;">b</span> = temp<span style="color: #000066; font-weight: bold;">;</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: #990000;">&quot;Assign swap time (new temp): &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: #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></pre></div></div>

<p>On the same Windows machine, I&#8217;m getting nearly identical times to the other version with a temporary variable. I&#8217;ve run it a couple dozen times and the difference is +/- 2 ms.</p>
<p>Thanks for the suggestion!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: grapefrukt</title>
		<link>http://jacksondunstan.com/articles/318/comment-page-1#comment-50</link>
		<dc:creator>grapefrukt</dc:creator>
		<pubDate>Mon, 21 Sep 2009 15:16:09 +0000</pubDate>
		<guid isPermaLink="false">http://jacksondunstan.com/?p=318#comment-50</guid>
		<description>I think you should do a version with the temporary var instantiated inside the loop, i&#039;m not able to test whether it would make any difference, but it should atleast make the comparison a bit more fair since that&#039;s the normal use case. 

But then again, since you&#039;re doing a hundred million iterations normal might be a misnomer ;)</description>
		<content:encoded><![CDATA[<p>I think you should do a version with the temporary var instantiated inside the loop, i&#8217;m not able to test whether it would make any difference, but it should atleast make the comparison a bit more fair since that&#8217;s the normal use case. </p>
<p>But then again, since you&#8217;re doing a hundred million iterations normal might be a misnomer ;)</p>
]]></content:encoded>
	</item>
</channel>
</rss>

