<?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>division &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/division/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>PHP Performance: Bitwise Division</title>
		<link>/2012/01/05/php-performance-bitwise-division/</link>
		<comments>/2012/01/05/php-performance-bitwise-division/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 15:38:13 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[bitwise operation]]></category>
		<category><![CDATA[bitwise operators]]></category>
		<category><![CDATA[division]]></category>
		<category><![CDATA[performance tests]]></category>
		<category><![CDATA[php performance]]></category>
		<category><![CDATA[research]]></category>

		<guid isPermaLink="false">/?p=2577</guid>
		<description><![CDATA[Recently I wrote about binary search and then I said that in some languages, like PHP, bitwise division by two is not faster than the typical “/” operator. However I decided to make some experiments and here are the results. Important Note It’s very important to say that the following results are dependant from the &#8230; <a href="/2012/01/05/php-performance-bitwise-division/" class="more-link">Continue reading <span class="screen-reader-text">PHP Performance: Bitwise Division</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2012/01/24/javascript-performance-for-vs-while/" rel="bookmark" title="JavaScript Performance: for vs. while">JavaScript Performance: for vs. while </a></li>
<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="/2009/12/30/jquery-live-vs-bind-performance/" rel="bookmark" title="jQuery live() vs bind() performance">jQuery live() vs bind() performance </a></li>
<li><a href="/2012/07/24/php-arrays-or-linked-lists/" rel="bookmark" title="PHP: Arrays or Linked Lists?">PHP: Arrays or Linked Lists? </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Recently I wrote about <a href="/2011/12/26/computer-algorithms-binary-search/" title="Computer Algorithms: Binary Search">binary search</a> and then I said that in some languages, like PHP, bitwise division by two is not faster than the typical “/” operator. However I decided to make some experiments and here are the results.</p>
<h2>Important Note</h2>
<p>It’s very important to say that the following results are dependant from the machine and the environment!</p>
<h2>Source Code</h2>
<p>Here&#8217;s the PHP source code.</p>
<pre lang="PHP">
function divide($n = 1) 
{
	$a = microtime(true);
	for ($i = 0; $i < $n; $i++) {
		300/2;
	}
	echo microtime(true) - $a;
}

divide(100);
//divide(1000);
//divide(10000);
//divide(100000);
//divide(1000000);
//divide(10000000);
</pre>
<p><span id="more-2577"></span><br />
and bitwise ...</p>
<pre lang="PHP">
function bitwise($n = 1)
{
	$a = microtime(true);
	for ($i = 0; $i < $n; $i++) {
		300 >> 1;
	}
	echo microtime(true) - $a;
}

bitwise(100);
//bitwise(1000);
//bitwise(10000);
//bitwise(100000);
//bitwise(1000000);
//bitwise(10000000);
</pre>
<p>Note that each method was called 6 times with the same parameter. This means that divide(100) was called 6 times and then I used the average value of these six times.</p>
<h2>Results</h2>
<p>I said back then in my binary search post, that in PHP the bitwise operator ">> 1" is not faster than the typical division with the "/" operator. However the results tells us that using bitwise division is slightly faster, as you can see at the diagram bellow.</p>
<pre lang="PHP">
n		">>"			"/"
100		0.0002334912618		0.000311803817749
1000		0.001911004384359	0.007335503896078
10000		0.013423800468445	0.039460102717081
100000		0.14417803287506	0.21413381894429
1000000		1.15839115778605	1.17152162392935
10000000	10.556711634		11.0911625623705
</pre>
<figure id="attachment_2596" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/01/bitwise-divide-by-two.png"><img src="/wp-content/uploads/2012/01/bitwise-divide-by-two.png" alt="PHP Performance: Bitwise division is slightly faster!" title="bitwise-divide-by-two" width="600" height="371" class="size-full wp-image-2596" srcset="/wp-content/uploads/2012/01/bitwise-divide-by-two.png 600w, /wp-content/uploads/2012/01/bitwise-divide-by-two-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text">Bitwise division is slightly faster!</figcaption></figure>
<h2>Conclusion</h2>
<p>Although bitwise division is a bit faster the difference is so small that you should work with very large data in order to gain some performance.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2012/01/24/javascript-performance-for-vs-while/" rel="bookmark" title="JavaScript Performance: for vs. while">JavaScript Performance: for vs. while </a></li>
<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="/2009/12/30/jquery-live-vs-bind-performance/" rel="bookmark" title="jQuery live() vs bind() performance">jQuery live() vs bind() performance </a></li>
<li><a href="/2012/07/24/php-arrays-or-linked-lists/" rel="bookmark" title="PHP: Arrays or Linked Lists?">PHP: Arrays or Linked Lists? </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/01/05/php-performance-bitwise-division/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
