<?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: Case study: Is PHP embarrasingly slower than Java?</title>
	<atom:link href="http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/feed/" rel="self" type="application/rss+xml" />
	<link>http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/</link>
	<description>no buzzwords allowed</description>
	<lastBuildDate>Wed, 01 Feb 2012 18:42:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: ÂÛÂÎÇ ÌÓÑÎÐÀ ÄÅÌÎÍÒÀÆ</title>
		<link>http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/comment-page-1/#comment-34446</link>
		<dc:creator>ÂÛÂÎÇ ÌÓÑÎÐÀ ÄÅÌÎÍÒÀÆ</dc:creator>
		<pubDate>Thu, 25 Nov 2010 16:49:56 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=140#comment-34446</guid>
		<description>&lt;strong&gt;ÂÛÂÎÇ ÌÓÑÎÐÀ ÄÅÌÎÍÒÀÆ...&lt;/strong&gt;

âûâîç ìóñîðà...</description>
		<content:encoded><![CDATA[<p><strong>ÂÛÂÎÇ ÌÓÑÎÐÀ ÄÅÌÎÍÒÀÆ&#8230;</strong></p>
<p>âûâîç ìóñîðà&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pierre</title>
		<link>http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/comment-page-1/#comment-18301</link>
		<dc:creator>Pierre</dc:creator>
		<pubDate>Mon, 07 Sep 2009 07:59:06 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=140#comment-18301</guid>
		<description>For a &quot;JaveRebel&quot;-like ANSI C tool, have a look at:

http://trustleap.ch/

And, before you ask, yes, ANSI C scripts are (much) faster than Java.</description>
		<content:encoded><![CDATA[<p>For a &#8220;JaveRebel&#8221;-like ANSI C tool, have a look at:</p>
<p><a href="http://trustleap.ch/" rel="nofollow">http://trustleap.ch/</a></p>
<p>And, before you ask, yes, ANSI C scripts are (much) faster than Java.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: מחשבות, מחשבים, ושאר דברי בלע &#187; Blog Archive &#187; משתמש תרם שיפורי ביצועים משמעותיים לIP2C</title>
		<link>http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/comment-page-1/#comment-1072</link>
		<dc:creator>מחשבות, מחשבים, ושאר דברי בלע &#187; Blog Archive &#187; משתמש תרם שיפורי ביצועים משמעותיים לIP2C</dc:creator>
		<pubDate>Wed, 13 Aug 2008 07:15:25 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=140#comment-1072</guid>
		<description>[...] העסק לילה שלם ושיפור את הביצועים של גרסאת הPHP ב150%. תומס כתב פוסט מעניין על השינויים שהוא עשה, ושלח לי את השינויים. [...]</description>
		<content:encoded><![CDATA[<p>[...] העסק לילה שלם ושיפור את הביצועים של גרסאת הPHP ב150%. תומס כתב פוסט מעניין על השינויים שהוא עשה, ושלח לי את השינויים. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Indrek Altpere</title>
		<link>http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/comment-page-1/#comment-1043</link>
		<dc:creator>Indrek Altpere</dc:creator>
		<pubDate>Fri, 08 Aug 2008 17:34:55 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=140#comment-1043</guid>
		<description>Well, with javarebel being out now, it speeds up development time (by removing need of full package redeployment to apply code changes) thus making it almost feel as an interpreted-on-the-fly language but still remaining as compiled language.
But then again, it comes at a price of performance overhead and thus is not advised to be used in production systems. So for production stuff, the undeploy/deploy phase will still remain there.

Generally, there is place for php and then there&#039;s place for java, depending on the purpose and amount of users for the site.
For some number crunching programs that need to be as fast a possible, java would be better choice than php, but in many cases to get better memory usage too, c would be best of all.

As for web applications, it is not as clear, both languages have advantages and disadvantages.
In java, you can have the server (tomcat, glassfish etc) host the site code, keeping all the main config data, translations, database entity classes etc in memory thus removing unnecessary reading of config files, language files, unneeded database hits/queries etc per each page generation.
Whereas in php you have to load everything for each page generation. But there are things to ease that: memcached server and php plugin/class to use it to store data, then there are cachers/optimizers to speed up script itself and reduce time spent on parsing php files (APC, eAccelerator, zend optimizer, ioncube etc). Main downside is that although they make php faster, they don&#039;t provide such thing as shared memory as in: have one database row referenced from two separately running php scripts. So if you have 10 scripts that need a row with id of 123, that row is queried from db 10 times (or from memcached 10 times) and after all that, it is taking up memory space in 10 different running scripts.
But as I said, this is not black and white thing, the fact that there does not exist a shared memory or php provided application scope makes it also less vulnerable to small/medium memory leaks because as you all know it, at the end of php script lifecycle, the process closes and releases al resources. So you can accidentaly have few circular references appearing for every invokation and still see server running happily. As in java (an all other similar long-running server providing languages as asp.net etc), few accidental circular references and unreleased resources may end up in webserver crash pretty soon because memory runs out even with small number of people visiting the site.

Don&#039;t get me wrong, I&#039;m not saying it&#039;s a good thing to be lazy and/or code badly, but what I have seen so far is that you can write WTF code and write buggy code in absolutely every coding language. Thus, because no one is flawless, it&#039;s actually good that php releases all resources after script completes, making it less error prone. Meaning if for every pageload a 100KB object/memory leak occurs, in php it would be no critical problem to bring the whole site down, but in java (and other similar) it would bring the site down quite easily, causing lots of headaches and financial losses.

So, all in all, both have negative and positive sides.
Java would be useful for sites that expect lots of users to view some certain pages or do some similar action at the same time so that the count of different objects in server&#039;s memory at one point in time would be optimal. Thus keeping the memory usage normal and site fast since every page load does not need to load up everything again and store same thing in many different places.
But when there are not so much requests coming in all at once but rather in a row with few spikes, php is very good to use, since it has nice fault tolerance for a bit unoptimized code and because of the fast deploy time (and with good IDE, quite similar development time to java coded in IDE).
The most positive thing about php I myself like, is the zero deploy time: when I find a piece of unoptimized code or need to do a little change in production (for example some function gets called twice instead once or some billing logic needs to be changed/fixed etc etc) I edit the file, change it, save it and be done with it.
As with java, the process would go generally like this: change code, compile, build production deployment package, upload it to java webserver (java webapps tend to grow quite big because of different libraries used so it takes usually quite some time unless you have production server in your own LAN), undeploy old application, deploy new one, check if all is ok.
And the worst part is, that unless you do some special setup or stuff so that sessions are stored somewhere between undeploy and deploy, all users on the website at that time will be logged out, all session data gets lost. AND depending on the system setup again, they will see some page reporting about site update being in progress or just some general webserver error page.

In general Java is indeed much (depending on program, sometimes very much) faster than PHP but when you don&#039;t have all the fancy frameworks and libraries to use in java, it is generally much easier to develop in php than in java. Not to mention the class autoloading feature in php with what you can divide complex codeflows to classes so that minimal number class definitions are loaded up at any point of time.

When using all of those nice and fancy framework, the fastness of java gets a hit plus the memory usage tends to get out of hands also because of the complexity of the codeflow that it takes to actually get to the part to run your function when user does something. I have seen stacktraces that have 50 to 150 or more lines in them, not a nice thing to see, and generally only 2 or 3 of those lines are actually about my own written code.
Plus the shiny and actually cool component-approach in java thanks to different libraries based on application scope (storing complex viewstate in memory between requests), is two-edge sword IMHO. Depending the complexity of the page, it takes some certain amount of requests (depending on page) without storing cookies, to fill up all the server memory with unused and useless viewstates/sessions.

Anyhow, both languages have their own places and situations where they are most effective and useful, but comparing a language made for creating websites fast and efficiently to a universal compiled language in a number-crunching test is lost cause upfront for the webpage creating languge :P But it does not mean that &quot;java is the best language for everything&quot; automatically ;) I bet some assembler code would be even faster but we don&#039;t see too many assembler written applications for some reason :P</description>
		<content:encoded><![CDATA[<p>Well, with javarebel being out now, it speeds up development time (by removing need of full package redeployment to apply code changes) thus making it almost feel as an interpreted-on-the-fly language but still remaining as compiled language.<br />
But then again, it comes at a price of performance overhead and thus is not advised to be used in production systems. So for production stuff, the undeploy/deploy phase will still remain there.</p>
<p>Generally, there is place for php and then there&#8217;s place for java, depending on the purpose and amount of users for the site.<br />
For some number crunching programs that need to be as fast a possible, java would be better choice than php, but in many cases to get better memory usage too, c would be best of all.</p>
<p>As for web applications, it is not as clear, both languages have advantages and disadvantages.<br />
In java, you can have the server (tomcat, glassfish etc) host the site code, keeping all the main config data, translations, database entity classes etc in memory thus removing unnecessary reading of config files, language files, unneeded database hits/queries etc per each page generation.<br />
Whereas in php you have to load everything for each page generation. But there are things to ease that: memcached server and php plugin/class to use it to store data, then there are cachers/optimizers to speed up script itself and reduce time spent on parsing php files (APC, eAccelerator, zend optimizer, ioncube etc). Main downside is that although they make php faster, they don&#8217;t provide such thing as shared memory as in: have one database row referenced from two separately running php scripts. So if you have 10 scripts that need a row with id of 123, that row is queried from db 10 times (or from memcached 10 times) and after all that, it is taking up memory space in 10 different running scripts.<br />
But as I said, this is not black and white thing, the fact that there does not exist a shared memory or php provided application scope makes it also less vulnerable to small/medium memory leaks because as you all know it, at the end of php script lifecycle, the process closes and releases al resources. So you can accidentaly have few circular references appearing for every invokation and still see server running happily. As in java (an all other similar long-running server providing languages as asp.net etc), few accidental circular references and unreleased resources may end up in webserver crash pretty soon because memory runs out even with small number of people visiting the site.</p>
<p>Don&#8217;t get me wrong, I&#8217;m not saying it&#8217;s a good thing to be lazy and/or code badly, but what I have seen so far is that you can write WTF code and write buggy code in absolutely every coding language. Thus, because no one is flawless, it&#8217;s actually good that php releases all resources after script completes, making it less error prone. Meaning if for every pageload a 100KB object/memory leak occurs, in php it would be no critical problem to bring the whole site down, but in java (and other similar) it would bring the site down quite easily, causing lots of headaches and financial losses.</p>
<p>So, all in all, both have negative and positive sides.<br />
Java would be useful for sites that expect lots of users to view some certain pages or do some similar action at the same time so that the count of different objects in server&#8217;s memory at one point in time would be optimal. Thus keeping the memory usage normal and site fast since every page load does not need to load up everything again and store same thing in many different places.<br />
But when there are not so much requests coming in all at once but rather in a row with few spikes, php is very good to use, since it has nice fault tolerance for a bit unoptimized code and because of the fast deploy time (and with good IDE, quite similar development time to java coded in IDE).<br />
The most positive thing about php I myself like, is the zero deploy time: when I find a piece of unoptimized code or need to do a little change in production (for example some function gets called twice instead once or some billing logic needs to be changed/fixed etc etc) I edit the file, change it, save it and be done with it.<br />
As with java, the process would go generally like this: change code, compile, build production deployment package, upload it to java webserver (java webapps tend to grow quite big because of different libraries used so it takes usually quite some time unless you have production server in your own LAN), undeploy old application, deploy new one, check if all is ok.<br />
And the worst part is, that unless you do some special setup or stuff so that sessions are stored somewhere between undeploy and deploy, all users on the website at that time will be logged out, all session data gets lost. AND depending on the system setup again, they will see some page reporting about site update being in progress or just some general webserver error page.</p>
<p>In general Java is indeed much (depending on program, sometimes very much) faster than PHP but when you don&#8217;t have all the fancy frameworks and libraries to use in java, it is generally much easier to develop in php than in java. Not to mention the class autoloading feature in php with what you can divide complex codeflows to classes so that minimal number class definitions are loaded up at any point of time.</p>
<p>When using all of those nice and fancy framework, the fastness of java gets a hit plus the memory usage tends to get out of hands also because of the complexity of the codeflow that it takes to actually get to the part to run your function when user does something. I have seen stacktraces that have 50 to 150 or more lines in them, not a nice thing to see, and generally only 2 or 3 of those lines are actually about my own written code.<br />
Plus the shiny and actually cool component-approach in java thanks to different libraries based on application scope (storing complex viewstate in memory between requests), is two-edge sword IMHO. Depending the complexity of the page, it takes some certain amount of requests (depending on page) without storing cookies, to fill up all the server memory with unused and useless viewstates/sessions.</p>
<p>Anyhow, both languages have their own places and situations where they are most effective and useful, but comparing a language made for creating websites fast and efficiently to a universal compiled language in a number-crunching test is lost cause upfront for the webpage creating languge :P But it does not mean that &#8220;java is the best language for everything&#8221; automatically ;) I bet some assembler code would be even faster but we don&#8217;t see too many assembler written applications for some reason :P</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Gilkison</title>
		<link>http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/comment-page-1/#comment-1040</link>
		<dc:creator>Jon Gilkison</dc:creator>
		<pubDate>Wed, 06 Aug 2008 18:54:57 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=140#comment-1040</guid>
		<description>Let me get this right.

If I can do the exact same thing you can, but I can deploy it 2x as fast as you, in 1/3rd the development time, in 1/4th the amount of code ... that is costing me what?  It isn&#039;t costing me salary, which I can put into hardware and still come out way ahead.

Java has it&#039;s places, don&#039;t get me wrong, but for most web apps I&#039;ll have to give a resounding &quot;meh&quot; when far easier, faster solutions are out there.</description>
		<content:encoded><![CDATA[<p>Let me get this right.</p>
<p>If I can do the exact same thing you can, but I can deploy it 2x as fast as you, in 1/3rd the development time, in 1/4th the amount of code &#8230; that is costing me what?  It isn&#8217;t costing me salary, which I can put into hardware and still come out way ahead.</p>
<p>Java has it&#8217;s places, don&#8217;t get me wrong, but for most web apps I&#8217;ll have to give a resounding &#8220;meh&#8221; when far easier, faster solutions are out there.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vjekoslav Nesek</title>
		<link>http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/comment-page-1/#comment-1039</link>
		<dc:creator>Vjekoslav Nesek</dc:creator>
		<pubDate>Wed, 06 Aug 2008 13:24:34 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=140#comment-1039</guid>
		<description>@Jon
Well I guess I&#039;m a bit of masochist. Sticking with Java since I tend to get a job done much faster in every sense of the word.

Regarding... apples vs. oranges stuff I&#039;ll aggree. Comparing PHP to Java performance is a complete waste of time and irrelevant. Java is 10-1000x faster on every computation bound task I can think of.

I was mostly interested to see how much performance can I extract from my lib when Thomas posted it&#039;s results.. This 8-140K lookups/s for Java version advertised on IP2C site looked really slow to me for such a simple task so I tried to optimize a bit to see how much further I can push it.

I&#039;ve learned something from it, for example that memory caching things can take 50% more RAM in 64bit JVM, that String interning can reduce it by half and that parsing String to InetAddress instances is a real performance killer.

@Jon... This quick-to-deploy attitude can cost you a lot of money when you need a farm of computers to run what a single machine can.

...and taking offense on a fact that PHP is slower than Java is a bit childish, wouldn&#039;t you agree?</description>
		<content:encoded><![CDATA[<p>@Jon<br />
Well I guess I&#8217;m a bit of masochist. Sticking with Java since I tend to get a job done much faster in every sense of the word.</p>
<p>Regarding&#8230; apples vs. oranges stuff I&#8217;ll aggree. Comparing PHP to Java performance is a complete waste of time and irrelevant. Java is 10-1000x faster on every computation bound task I can think of.</p>
<p>I was mostly interested to see how much performance can I extract from my lib when Thomas posted it&#8217;s results.. This 8-140K lookups/s for Java version advertised on IP2C site looked really slow to me for such a simple task so I tried to optimize a bit to see how much further I can push it.</p>
<p>I&#8217;ve learned something from it, for example that memory caching things can take 50% more RAM in 64bit JVM, that String interning can reduce it by half and that parsing String to InetAddress instances is a real performance killer.</p>
<p>@Jon&#8230; This quick-to-deploy attitude can cost you a lot of money when you need a farm of computers to run what a single machine can.</p>
<p>&#8230;and taking offense on a fact that PHP is slower than Java is a bit childish, wouldn&#8217;t you agree?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lomo</title>
		<link>http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/comment-page-1/#comment-1038</link>
		<dc:creator>lomo</dc:creator>
		<pubDate>Wed, 06 Aug 2008 12:42:58 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=140#comment-1038</guid>
		<description>I have no compsci lic., but I tend to agree with Jon.

If you are comparing performance between compiled Java versus interpreted PHP, then it&#039;s only fair that you also took PHP optimizer like Zend or a bunch others here into considerations :
http://en.wikipedia.org/wiki/PHP_accelerator

Zend claims 25x performance, so does that makes PHP faster than Java?

Doesn&#039;t matter how far you optimize a script, they will never be the same, and this comparison is just plain silly.</description>
		<content:encoded><![CDATA[<p>I have no compsci lic., but I tend to agree with Jon.</p>
<p>If you are comparing performance between compiled Java versus interpreted PHP, then it&#8217;s only fair that you also took PHP optimizer like Zend or a bunch others here into considerations :<br />
<a href="http://en.wikipedia.org/wiki/PHP_accelerator" rel="nofollow">http://en.wikipedia.org/wiki/PHP_accelerator</a></p>
<p>Zend claims 25x performance, so does that makes PHP faster than Java?</p>
<p>Doesn&#8217;t matter how far you optimize a script, they will never be the same, and this comparison is just plain silly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Toomas Römer</title>
		<link>http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/comment-page-1/#comment-1037</link>
		<dc:creator>Toomas Römer</dc:creator>
		<pubDate>Wed, 06 Aug 2008 12:05:34 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=140#comment-1037</guid>
		<description>From the point of trying to optimize a script to get as close as possible to the other implementation this is all valid.

Had I started it in the sense of lets compare PHP &amp; Java, I would have done it differently.

I&#039;m revoking my compsci revokation.</description>
		<content:encoded><![CDATA[<p>From the point of trying to optimize a script to get as close as possible to the other implementation this is all valid.</p>
<p>Had I started it in the sense of lets compare PHP &#038; Java, I would have done it differently.</p>
<p>I&#8217;m revoking my compsci revokation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Gilkison</title>
		<link>http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/comment-page-1/#comment-1036</link>
		<dc:creator>Jon Gilkison</dc:creator>
		<pubDate>Wed, 06 Aug 2008 11:46:56 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=140#comment-1036</guid>
		<description>Are you kidding me?

You&#039;re comparing a JIT&#039;d VM based language versus an interpreted dynamically typed scripting language?  And you&#039;re shocked the performance is so off?

If they had compsci licenses I would ask for yours to be revoked because you obviously don&#039;t get it.

You choose PHP because it&#039;s easy and fast to develop.   You choose Java because you have a penchant for self mutilation and are a bit of a masochist.

The only valid comparison you can make here is how quickly it took you to wrote and deploy.  Measuring performance is just pure idiocy.</description>
		<content:encoded><![CDATA[<p>Are you kidding me?</p>
<p>You&#8217;re comparing a JIT&#8217;d VM based language versus an interpreted dynamically typed scripting language?  And you&#8217;re shocked the performance is so off?</p>
<p>If they had compsci licenses I would ask for yours to be revoked because you obviously don&#8217;t get it.</p>
<p>You choose PHP because it&#8217;s easy and fast to develop.   You choose Java because you have a penchant for self mutilation and are a bit of a masochist.</p>
<p>The only valid comparison you can make here is how quickly it took you to wrote and deploy.  Measuring performance is just pure idiocy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Toomas Römer</title>
		<link>http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/comment-page-1/#comment-1034</link>
		<dc:creator>Toomas Römer</dc:creator>
		<pubDate>Tue, 05 Aug 2008 20:25:24 +0000</pubDate>
		<guid isPermaLink="false">http://dow.ngra.de/?p=140#comment-1034</guid>
		<description>@aspect - There are some results to SQLite being used for the binary searching http://www.reddit.com/r/programming/comments/6usfd/case_study_is_php_embarrasingly_slower_than_java/</description>
		<content:encoded><![CDATA[<p>@aspect &#8211; There are some results to SQLite being used for the binary searching <a href="http://www.reddit.com/r/programming/comments/6usfd/case_study_is_php_embarrasingly_slower_than_java/" rel="nofollow">http://www.reddit.com/r/programming/comments/6usfd/case_study_is_php_embarrasingly_slower_than_java/</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

