<?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>Increment &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/increment/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>JavaScript Performance: for vs. while</title>
		<link>/2012/01/24/javascript-performance-for-vs-while/</link>
		<comments>/2012/01/24/javascript-performance-for-vs-while/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 14:20:05 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Control flow]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[Increment]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[software/hardware]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[While loop]]></category>

		<guid isPermaLink="false">/?p=2635</guid>
		<description><![CDATA[JavaScript Loops If you have read some preformance tests on JavaScript loops, you may have heard that &#8220;while&#8221; is faster than &#8220;for&#8221;. However the question is how faster is &#8220;while&#8221;? Here are some results, but first let&#8217;s take a look on the JavaScript code. The for experiment console.time('for'); for (var i = 0; i < &#8230; <a href="/2012/01/24/javascript-performance-for-vs-while/" class="more-link">Continue reading <span class="screen-reader-text">JavaScript Performance: for vs. while</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/" rel="bookmark" title="Profiling JavaScript with Firebug. console.profile() &#038; console.time()!">Profiling JavaScript with Firebug. console.profile() &#038; console.time()! </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/06/02/detecting-pressed-key-with-e-which-in-javascript/" rel="bookmark" title="Detecting Pressed Key with e.which in JavaScript">Detecting Pressed Key with e.which in JavaScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>JavaScript Loops</h2>
<p>If you have read some preformance tests on JavaScript loops, you may have heard that &#8220;while&#8221; is faster than &#8220;for&#8221;. However the question is how faster is &#8220;while&#8221;? Here are some results, but first let&#8217;s take a look on the JavaScript code. </p>
<h4>The <strong>for</strong> experiment</h4>
<pre lang="javascript">
console.time('for');
for (var i = 0; i < 10000000; i++) {
	i / 2;
}
console.timeEnd('for');
</pre>
<h4>The <strong>while</strong> experiment</h4>
<pre lang="javascript">
console.time('while');
var i = 0;
while (i++ < 10000000) {
	i / 2;
}
console.timeEnd('while');
</pre>
<p>Note - these tests are performed and measured with Firebug on Firefox.</p>
<h2>Results</h2>
<p>It's a fact, that you'll get different results as many times as you run this snippet. It depends also on the enviroment and software/hardware specs. That is why I performed them 10 times and then I took the average value. Here are the values of my performance tests. Note that both <strong>for</strong> and <strong>while</strong> perform 10,000,000 iterations.</p>
<p><iframe width='576' height='263' frameborder='0' src='https://docs.google.com/spreadsheet/pub?hl=en_US&#038;hl=en_US&#038;key=0Avxdu4aY4-UGdDktZEJHYUh5RWFLd1prOG52dDdTdUE&#038;single=true&#038;gid=0&#038;output=html&#038;widget=true'></iframe></p>
<h2>And the Winner Is</h2>
<p><strong>While</strong> is the winner with an average result of 83.5 milliseconds, while "for" result is 88 average milliseconds.</p>
<p>As the diagram bellow shows, <strong>the while loop is slightly faster</strong>. However we should be aware that these performance gains are significant for large number of iterations!</p>
<figure id="attachment_2668" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/01/chart_1-1.png"><img src="/wp-content/uploads/2012/01/chart_1-1.png" alt="JavaScript Performance: for vs. while" title="JavaScript Performance: for vs. while" width="600" height="371" class="size-full wp-image-2668" srcset="/wp-content/uploads/2012/01/chart_1-1.png 600w, /wp-content/uploads/2012/01/chart_1-1-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text">JavaScript Performance: for vs. while</figcaption></figure>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/" rel="bookmark" title="Profiling JavaScript with Firebug. console.profile() &#038; console.time()!">Profiling JavaScript with Firebug. console.profile() &#038; console.time()! </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/06/02/detecting-pressed-key-with-e-which-in-javascript/" rel="bookmark" title="Detecting Pressed Key with e.which in JavaScript">Detecting Pressed Key with e.which in JavaScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/01/24/javascript-performance-for-vs-while/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
