Live data from Hacker News

PHP Performance Benchmarks

maettig.com

21–30 of 49 posts

Re: PHP Performance Benchmarks

#21
post #9

Earlier quoted context omitted.

There are some similar benchmark here: http://www.phpbench.com/ Intuitively the for loop should be a lot fast as it isn't assigning anything each loop. Although in your example it may be slower because the count($users) would be ran on each iteration of the loop.

It only assigns $user in a foreach when the $user is modified, or if you are trying to outsmart PHP-core and use & to pass it as a reference.

I get what you mean, but it might be helpful to translate it for everybody else:

Foreach is doing an assignment in each iteration, robryan is right. But PHP variables are copy-on-write so $user is, until modified, just an entry in the symbol table which is very fast.

And that for() loop also has an assignment -- the incrementer.

Re: PHP Performance Benchmarks

#22
post #10

I got excited at first because I thought it was a standalone script that benchmarked a server. Does anybody know of a script that will score a server based on cpu/io/memory/etc? Would be a great way to see if a server is properly configured or what kind of performance to expect from a cloud solution.

The difference between php-5.2 (the version used), php-5.3, and php-5.4 is quite vast for each version, especially since php-5.4 basically cut memory usage/execution time by a third at worst (or directly by half at best) when compared to php-5.3.

This is purely anecdotal but I use PHP for large scripts doing lots of inserts/deletes (>100,000) from databases and relatively simple logic.

Re: PHP Performance Benchmarks

#23
post #16

I got this site bookmarked from a long time ago so I do not know what is the PHP version tested. Adding it because it seems to contain quite alot of different tests. http://net-beta.net/ubench/

According to the request headers it's using php-5.3.13 (released May 2012).

Re: PHP Performance Benchmarks

#24
post #6
post #3

What am I supposed to learn from these numbers? They are interesting to look at, but I don't have enough information. Exactly what version of php is running, and how is it configured? What does the "Index" field signify? Where can I find the code? While fun to look at and calculate, it also doesn't mean a lot for most applications. I would argue that data fetching from DBs or caches will be the majority of execution…

> I would argue that data fetching from DBs or caches will be the majority of execution time. People keep saying that, and I would like to see some numbers for that also. The DB dataset could be already cached in memory, for example.

Database access latency will always trump any language design issues, except in extreme cases. This article does make some of those cases obvious, especially since they are easily-overlooked programming mistakes.

Re: PHP Performance Benchmarks

#25
post #2

this is interesting, I'd like to see a comparison with foreach vs. for too - just out of curiousity :) Also the $var == "" kind of suprised me, didn't know it was that bad, although I guess this does rarely happen since most probably use empty anyway.

The $var == "" issue is more understandable when you realize that PHP attempts to do type coercion to test comparison for all data types, while the equality operator (triple equals, ===) does not attempt to do type coercion.

Also, foreach(range(1, 1000 * 1000) as $i) will execute at roughly the same speed as for($i = 0, $count = 1000 * 1000; $i < $count; $i++), so the difference is negligible.

Re: PHP Performance Benchmarks

#26
post #6
post #3

What am I supposed to learn from these numbers? They are interesting to look at, but I don't have enough information. Exactly what version of php is running, and how is it configured? What does the "Index" field signify? Where can I find the code? While fun to look at and calculate, it also doesn't mean a lot for most applications. I would argue that data fetching from DBs or caches will be the majority of execution…

> I would argue that data fetching from DBs or caches will be the majority of execution time. People keep saying that, and I would like to see some numbers for that also. The DB dataset could be already cached in memory, for example.

Large web apps do often spend a lot of time manipulating strings and arrays in memory. It's absolutely true and I've seen it myself several times -- a performance penalty that is measurable and noticeable to users.

But that pales in comparison to the overhead of a Database call, or even a call to Redis or Memcached.

I've read (from sources I trust) that a database call on a modern stack like .Net or JVM is 4 orders of magnitude slower than a local method call. Think about that. So if the time you spend brushing your teeth is a local method call, the entire next day is a database query.

I can't remember the source here but the information is available with a few minutes of coding or googling.

And to the caching point -- having data cached locally in memory is great, but you can't trust that.

Re: PHP Performance Benchmarks

#28
post #22
post #10

I got excited at first because I thought it was a standalone script that benchmarked a server. Does anybody know of a script that will score a server based on cpu/io/memory/etc? Would be a great way to see if a server is properly configured or what kind of performance to expect from a cloud solution.

The difference between php-5.2 (the version used), php-5.3, and php-5.4 is quite vast for each version, especially since php-5.4 basically cut memory usage/execution time by a third at worst (or directly by half at best) when compared to php-5.3. This is purely anecdotal but I use PHP for large scripts doing lots of inserts/deletes (>100,000) from databases and relatively simple logic.

Nice, I'll have to give 5.4 a try. Currently using 5.3, and finding it memory hogging when doing a lot of database operations in a row (300k+).

Re: PHP Performance Benchmarks

#29

Earlier quoted context omitted.

I just coded up a benchmark and posted the ProTip on coderwall. http://coderwall.com/p/il1tog

You're re-calculating the count() on each iteration. Of course it's slower. Fix that: for($i = 0; $count = count($elements); $i

Yeah I know, done purposefully to see how MUCH slower this is. This is how the majority of code is written in the wild, rarely do you see the `count()` pulled outside of the `for()`.
Post reply on HN