Live data from Hacker News

PHP Performance Benchmarks

maettig.com

41–49 of 49 posts

Re: PHP Performance Benchmarks

#41

   My conclusion: count() is horribly slow. Always precalculate it, if possible.
https://github.com/php/php-src/blob/master/ext/standard/arra...

In PHP they actually check the length of an array at every invocation of count(). As far as I can see the numeric value for length isn't stored anywhere.

Re: PHP Performance Benchmarks

#42
post #41

My conclusion: count() is horribly slow. Always precalculate it, if possible. https://github.com/php/php-src/blob/master/ext/standard/arra... In PHP they actually check the length of an array at every invocation of count(). As far as I can see the numeric value for length isn't stored anywhere.

In default, non recursive mode, it's only returning the value of zval->nNumOfElements (with a few indirections).

It's not count() that's benchmarked here, its the difference between "$a < $b" and "$a < function_call($b)".

Re: PHP Performance Benchmarks

#43
post #28
post #22

Earlier quoted context omitted.

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+).

Sadly, PHP 5.4 stills fails badly with APC in several cases, so I do not consider it ready for production yet

Re: PHP Performance Benchmarks

#44
post #43
post #28

Earlier quoted context omitted.

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+).

Sadly, PHP 5.4 stills fails badly with APC in several cases, so I do not consider it ready for production yet

Do you have any links to the bugs? We use 5.4 in production and haven't had any issues with APC, so I'm curious if we're missing anything relevant to our use case.

Re: PHP Performance Benchmarks

#45

Earlier quoted context omitted.

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()`.

This is simply unfair, should the language maintainers be held accountable for user behaviour? A more interesting and fairer topic is whether PHPs count() is considerably slower than python's len()

Re: PHP Performance Benchmarks

#46

Two wrong conclusions: === is infinitely better than empty() due to less glitchy behavior. don't use empty, ever. Numeric arrays in PHP are AS SLOW as associative array, that's pure fail and one of the reasons PHP::fannkuch is so slow.

They're implemented using the same data structure and given the language semantics (keys can be any scalar type intermingled horribly), how would you improve that?

Re: PHP Performance Benchmarks

#47
post #43
post #28

Earlier quoted context omitted.

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+).

Sadly, PHP 5.4 stills fails badly with APC in several cases, so I do not consider it ready for production yet

> Sadly, PHP 5.4 stills fails badly with APC in several cases, so I do not consider it ready for production yet

You're using outdated APC code. Update to the latest, it resolves issues with the 5.4 line. We use it in production, zero issues.

Re: PHP Performance Benchmarks

#48
post #34

Earlier quoted context omitted.

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 o…

> And to the caching point -- having data cached locally in memory is great, but you can't trust that. You can if you design around handling a possibly-stale cache.

Not really. There is no system that ever has had an always-fresh cache.

Are you disputing the premise or just disagreeing for the sake of it?

Re: PHP Performance Benchmarks

#49
post #34

Earlier quoted context omitted.

> And to the caching point -- having data cached locally in memory is great, but you can't trust that. You can if you design around handling a possibly-stale cache.

Not really. There is no system that ever has had an always-fresh cache. Are you disputing the premise or just disagreeing for the sake of it?

I'm saying that having a stale cache won't be a problem for an application that is designed around the fact that you will occasionally have stale data.
Post reply on HN