<?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>Flash, Flex and ActionScript tutorials - flashadvanced &#187; optimization</title>
	<atom:link href="http://flashadvanced.com/tag/optimization/feed/" rel="self" type="application/rss+xml" />
	<link>http://flashadvanced.com</link>
	<description>Become an advanced actionscript developer</description>
	<lastBuildDate>Sun, 30 Jan 2011 21:10:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ActionScript 3 optimization tips</title>
		<link>http://flashadvanced.com/actionscript-3-optimization-tips/</link>
		<comments>http://flashadvanced.com/actionscript-3-optimization-tips/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 12:39:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced ActionScript 3]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://flashadvanced.com/?p=69</guid>
		<description><![CDATA[This article will show you a collection of optimization tips for ActionScrip 3 that you can use to speed up your application&#8217;s performance. Let&#8217;s begin with the first rule in AS 3 optimization tehniques: 1. Use integers for iterations. Int type performs faster than Number when looping through the items of an array. This is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flashadvanced.com/?p=69"><br />
<img src="http://www.flashadvanced.com/wp-content/upload/optimization/optimization.jpg" alt="" /><br />
</a></p>
<p>This article will show you a collection of optimization tips for ActionScrip 3 that you can use to speed up your application&#8217;s <strong>performance</strong>.</p>
<p>Let&#8217;s begin with the first rule in AS 3 optimization tehniques:</p>
<p><span id="more-69"></span></p>
<p><span style="color: #ff0000;">1.</span> Use integers for <strong>iterations</strong>. Int type performs faster than Number when looping through the items of an array. This is because array indexing is faster with ints.</p>
<pre><code>for(var i:int = 0; i < 1000000; i++);</code></pre>
<p><span style="color: #ff0000;">2.</span> Use shorthand operators whenever possible</p>
<p>Incrementing is faster using the "++" operator than using "i = i + 1". It is the same situation with "a += b" which is faster than "a = a + b";</p>
<p><span style="color: #ff0000;">3.</span> Use <strong>multiplication</strong> instead of division when dividing by 2.</p>
<p>In this case it is better to use multiplication with .5 than division by 2.</p>
<p>Slow:</p>
<pre><code>var a:Number = b / 2;</code></pre>
<p>Fast:</p>
<pre><code>var a:Number = b*.5;</code></pre>
<p><span style="color: #ff0000;">4.</span> Use bitwise shift operators for even faster performance.</p>
<p>Slow:</p>
<pre><code>
var a:int = 10;
a = a * 2; //returns 20
a = a * 4; //returns 40
a = a / 2; //returns 5;</code></pre>
<p>Fast:</p>
<pre><code>
var a:int = 10;
a = a << 1; //returns 20
a = a << 2; //returns 40
a = a >> 1; //returns 5</code></pre>
<p><span style="color: #ff0000;">5.</span> Use single line variable declaration</p>
<p>Slow:</p>
<pre><code>
var a:int = 1;
var b:int = 2;
var c:int = 3;</code></pre>
<p>Fast:</p>
<p>First use the "var" keyword and then declare the variables on a single line.</p>
<pre><code>var a:int = 1, b:int = 2, c:int = 3;</code></pre>
<p><span style="color: #ff0000;">6.</span> Use "null" intead of "try .. catch" if possible:</p>
<pre><code>var myArray:Array;
if(myArray != null)
	myArray.pop();
else
	trace("its null");
</code></pre>
<p>is way <strong>faster</strong> than:</p>
<pre><code>try{
	myArray.pop();
}catch(e:Error){
	trace(e.message);
}</code></pre>
<p><span style="color: #ff0000;">7.</span>Use <strong>int(a)</strong> instead of <strong>Math.floor(a)</strong>. Math.floor(a) is 10 times slower than int(a).<br />
Slow:</p>
<pre><code>
for(var i:int=0; i<1000000; i++){
	var a:int = Math.floor(1.5);
}
</code></pre>
<p>Fast:</p>
<pre><code>
for(var i:int=0; i<1000000; i++){
	var a:int = int(1.5);
}
</code></pre>
<h4>This is how you can test your code performance:</h4>
<pre><code>
for(var i:int=0; i<1000000; i++){
	var a:int = 4 << 1;
	var b:int = 4 << 2;
	var c:int = 4 >> 1;
}
trace(getTimer());
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://flashadvanced.com/actionscript-3-optimization-tips/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

