<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.3" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: More Tips for faster PHP scripts</title>
	<link>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/</link>
	<description>About making the web a useful and interactive experience</description>
	<pubDate>Wed, 20 Aug 2008 11:05:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.3</generator>
		<item>
		<title>By: Mike</title>
		<link>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-5349</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Thu, 29 May 2008 15:25:53 +0000</pubDate>
		<guid>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-5349</guid>
		<description>Here I call shenanigans on #6, I ran the same test myself over 100,000,000 iterations each:

HomeOne:/srv/www/lighttpd/homeone# php ./test.php
The preincrement loop took: 15.85929107666 seconds.

The postincrement loop too: 16.909289121628 seconds.

The difference is: 6.6207123628175%

I ran this a number of times and got values ranging from 4-6%.

4-6% != 21%</description>
		<content:encoded><![CDATA[<p>Here I call shenanigans on #6, I ran the same test myself over 100,000,000 iterations each:</p>
<p>HomeOne:/srv/www/lighttpd/homeone# php ./test.php<br />
The preincrement loop took: 15.85929107666 seconds.</p>
<p>The postincrement loop too: 16.909289121628 seconds.</p>
<p>The difference is: 6.6207123628175%</p>
<p>I ran this a number of times and got values ranging from 4-6%.</p>
<p>4-6% != 21%</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Consigli per script PHP più veloci</title>
		<link>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-3713</link>
		<dc:creator>Consigli per script PHP più veloci</dc:creator>
		<pubDate>Mon, 21 Apr 2008 19:52:04 +0000</pubDate>
		<guid>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-3713</guid>
		<description>[...] ho deciso di prendere spunto da tre articoli che trovai tempo fa su come ottimizzare la scrittura di codice PHP, verificare, e [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] ho deciso di prendere spunto da tre articoli che trovai tempo fa su come ottimizzare la scrittura di codice PHP, verificare, e [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Веб-обзор #11: Silverlight 2, стартапы, как создавали успешные проекты и типология социальных проектов. &#124; Alpha-Beta-Release Blog</title>
		<link>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-2520</link>
		<dc:creator>Веб-обзор #11: Silverlight 2, стартапы, как создавали успешные проекты и типология социальных проектов. &#124; Alpha-Beta-Release Blog</dc:creator>
		<pubDate>Thu, 06 Mar 2008 22:09:26 +0000</pubDate>
		<guid>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-2520</guid>
		<description>[...] for faster PHP Scripts - сборник в трёх частях (2 и 3) различных небольших приёмов и техник для [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] for faster PHP Scripts - сборник в трёх частях (2 и 3) различных небольших приёмов и техник для [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Funciones PHP: Optimizar c</title>
		<link>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-2503</link>
		<dc:creator>Funciones PHP: Optimizar c</dc:creator>
		<pubDate>Thu, 06 Mar 2008 13:22:02 +0000</pubDate>
		<guid>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-2503</guid>
		<description>[...] Separaciones: split() permite utilizar expresiones regulares, mientras que explode() no. Intenta utilizar explode siempre antes que la funci</description>
		<content:encoded><![CDATA[<p>[&#8230;] Separaciones: split() permite utilizar expresiones regulares, mientras que explode() no. Intenta utilizar explode siempre antes que la funci</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-2100</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Tue, 26 Feb 2008 22:36:48 +0000</pubDate>
		<guid>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-2100</guid>
		<description>Apart from the date("U") vs. time() thing, none of those improvements are worth the time it takes to even think about them.

It's great that you have taken the time to prove that there is no practical difference between a for() loop and a while() loop.  It's always worthwhile double checking to make sure your guesses are correct.  What this shows is that you should write your PHP for readability and maintainability and use code profiling tools afterwards to optimise only where it is needed.

You could spend weeks rewriting all your code to use do...while() loops instead of for() loops and end up saving a grand total of a minute of CPU time each day.  If you had spent the same time using XDebug you would have realised that 90% of the page generation time is spent in mysql_query() calls and you should have been optimising your SQL or caching the results.

When I find code that is causing problems because it's taking too long, it is usually something like a for() loop that iterates over an entire database table and discards 90% of the rows where it would be much more efficient to rewrite the SQL query to only return the 10% of the rows you actually want.  Sometimes it's a snippet of code that writes and reads from the same database table, meaning that when you have lots of instances of this code running, they all have to wait for the table to be unlocked.  (MyISAM can't do concurrent reads and writes)  Sometimes it's PHP writing to a file over an NFS mounted directory that several webservers all write to.

When you're optimising code, run benchmarks, run profiling tools and pick the low-hanging fruit.

...and seriously, who would use date("U") instead of time() ?</description>
		<content:encoded><![CDATA[<p>Apart from the date(&#034;U&#034;) vs. time() thing, none of those improvements are worth the time it takes to even think about them.</p>
<p>It&#039;s great that you have taken the time to prove that there is no practical difference between a for() loop and a while() loop.  It&#039;s always worthwhile double checking to make sure your guesses are correct.  What this shows is that you should write your PHP for readability and maintainability and use code profiling tools afterwards to optimise only where it is needed.</p>
<p>You could spend weeks rewriting all your code to use do&#8230;while() loops instead of for() loops and end up saving a grand total of a minute of CPU time each day.  If you had spent the same time using XDebug you would have realised that 90% of the page generation time is spent in mysql_query() calls and you should have been optimising your SQL or caching the results.</p>
<p>When I find code that is causing problems because it&#039;s taking too long, it is usually something like a for() loop that iterates over an entire database table and discards 90% of the rows where it would be much more efficient to rewrite the SQL query to only return the 10% of the rows you actually want.  Sometimes it&#039;s a snippet of code that writes and reads from the same database table, meaning that when you have lots of instances of this code running, they all have to wait for the table to be unlocked.  (MyISAM can&#039;t do concurrent reads and writes)  Sometimes it&#039;s PHP writing to a file over an NFS mounted directory that several webservers all write to.</p>
<p>When you&#039;re optimising code, run benchmarks, run profiling tools and pick the low-hanging fruit.</p>
<p>&#8230;and seriously, who would use date(&#034;U&#034;) instead of time() ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Making the web &#187; Tips for faster PHP scripts</title>
		<link>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-1378</link>
		<dc:creator>Making the web &#187; Tips for faster PHP scripts</dc:creator>
		<pubDate>Tue, 12 Feb 2008 16:45:03 +0000</pubDate>
		<guid>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-1378</guid>
		<description>[...] post is part 1 of a 3 part series. For the other parts, visit these posts: More Tips for faster PHP scripts Even More Tips for faster PHP [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] post is part 1 of a 3 part series. For the other parts, visit these posts: More Tips for faster PHP scripts Even More Tips for faster PHP [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alton</title>
		<link>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-960</link>
		<dc:creator>Alton</dc:creator>
		<pubDate>Fri, 18 Jan 2008 17:42:10 +0000</pubDate>
		<guid>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-960</guid>
		<description>Great info for a nooB like me. Thanks for the article.</description>
		<content:encoded><![CDATA[<p>Great info for a nooB like me. Thanks for the article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex Howell</title>
		<link>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-559</link>
		<dc:creator>Alex Howell</dc:creator>
		<pubDate>Thu, 20 Dec 2007 13:19:55 +0000</pubDate>
		<guid>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-559</guid>
		<description>Re: Point five: it might be pointed out that pre incrementing and post incrementing return different values: pre incrementing returns the incremented value, post the original value.

Re: Point six:
What exactly are you testing? Are you incrementing one variable ten million times, or incrementing one value a million times? Or a range of values a million times? A benchmark of iterating from 1-1,000,000 isn't accurate because no-one is ever going to do that- PHP's designers wont have optimized the language for that.
Going from 1 to -1,000,000 will be different from 1,000,000 to 1 because the underlying data type has to be changed from unsigned to signed, which has a memory overhead.
Specifying whether the var is an int or a float will make a difference. I would also imagine that there will be different data types used for larger numbers (floats, doubles, reals etc) which will each have different performance characteristics.
The test is only meaningful if it is done with a realistic scenario.

Re Point 7:
As the manual gracefully points out; preg is most often faster than ereg in any case. It's actually quite a useful thing to have around.</description>
		<content:encoded><![CDATA[<p>Re: Point five: it might be pointed out that pre incrementing and post incrementing return different values: pre incrementing returns the incremented value, post the original value.</p>
<p>Re: Point six:<br />
What exactly are you testing? Are you incrementing one variable ten million times, or incrementing one value a million times? Or a range of values a million times? A benchmark of iterating from 1-1,000,000 isn&#039;t accurate because no-one is ever going to do that- PHP&#039;s designers wont have optimized the language for that.<br />
Going from 1 to -1,000,000 will be different from 1,000,000 to 1 because the underlying data type has to be changed from unsigned to signed, which has a memory overhead.<br />
Specifying whether the var is an int or a float will make a difference. I would also imagine that there will be different data types used for larger numbers (floats, doubles, reals etc) which will each have different performance characteristics.<br />
The test is only meaningful if it is done with a realistic scenario.</p>
<p>Re Point 7:<br />
As the manual gracefully points out; preg is most often faster than ereg in any case. It&#039;s actually quite a useful thing to have around.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-506</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Tue, 18 Dec 2007 03:35:35 +0000</pubDate>
		<guid>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-506</guid>
		<description>Thanks for the tips!  They will help a lot while I'm learning php!</description>
		<content:encoded><![CDATA[<p>Thanks for the tips!  They will help a lot while I&#039;m learning php!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johny</title>
		<link>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-475</link>
		<dc:creator>Johny</dc:creator>
		<pubDate>Mon, 17 Dec 2007 17:12:38 +0000</pubDate>
		<guid>http://bitfilm.net/2007/09/07/more-tips-for-faster-php-scripts/#comment-475</guid>
		<description>Thanks a lot , for the valuable information</description>
		<content:encoded><![CDATA[<p>Thanks a lot , for the valuable information</p>
]]></content:encoded>
	</item>
</channel>
</rss>
