You are here: Re: what is better for performance? « PHP « IT news, forums, messages
Re: what is better for performance?

Posted by Oliver Grδtz on 12/07/05 06:06

Karel Kozlik schrieb:
> Hi,
> I am just thinking about that what is better for storeing structured
> variables in point of view of performance.
>
> Is better store structured variables in associative array, for example:
>
> $person['first_name'] = 'Karel';
> $person['last_name'] = 'Kozlik';
> $person['address'] = 'somewhere on Earth';
>
> or in object like this:
>
> $person->first_name = 'Karel';
> $person->last_name = 'Kozlik';
> $person->address = 'somewhere on Earth';
>
> I feel that objects are better for performance, but work with
> associative arrays is pleasanter for me. May be the diference in
> performance measurable? (in heavy loaded environment)

First of all: You are already using something like eAccelerator? You
have optimized your database queries to take full advantage of the query
cache in your DBMS? You are using a userland cache to increase the
performance for seldomly changing content? If the question is "No" to
these or similar questions: Don't waste your time on thinking about
performance differences in the microsecond range! Unless your site
really has to take some hundred thousand page requests a day this is
just silly.

Now for the concept of array vs. attributes: I used to prefer the array
notation, too. But think about this: Arrays suggest some similarity
between the array elements, it suggest the elements are somewhat of the
same type. On the other side attributes are just that: Attributes of an
entity. So, it's more appropriate to use array notation for a
collections of persons but not for the attributes of a single person.
This started to change my mind about using array syntax here. Besides,
using -> saves you two keystrokes/bytes.

OK, that was for conceptual view. Now technical ;-)
The performance depends on the version of PHP you are using. For PHP4,
classes and objects are very much like arrays in disguise, it's only
with the Zend Engine 2 of PHP5 that this has changed. This engine has
greatly improved performance in PHP 5.1, so yeah, with PHP5.1 attributes
could be quicker than arrays BUT you shouldn't care ;-)

But remember: Always prefer concept to performance when designing
software. Performance considerations are welcome and important for the
large scale (as in "you shouldn't fetch all the rows in a table if you
display only ten of them => use LIMIT") but micro-profiling is
definitely something you should do when the system's up and running.

OLLi

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация