Re: Hidden costs of PHP arrays?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Clancy wrote:
Also what the relative virtues of defining the same set of fields for every contact, as
against either defining only the fields which actually hold values, as in the following
examples?

a:
$contacts['clancy']['home_address'] = 'jkjkjk';
$contacts['clancy']['home_phone'] = 0123 4567;
$contacts['clancy'][' office_address''] = '';
$contacts['clancy']['office_phone'] = '';
$contacts['joe']['home_address'] = '';
$contacts['joe']['home_phone'] = '';
$contacts['joe']['office_address'] = 'jsfvkl';
$contacts['joe']['office_phone'] = 'jsfvkl';

b;
$contacts['clancy']['home_phone'] = 0123 4567;
$contacts['clancy']['home_address'] = 'jkjkjk';
$contacts['joe']['office_address'] = 'jsfvkl';
$contacts['joe']['office_phone'] = 'jsfvkl';


if you go for option b; you're going to have do a vast amount of isset() checks in a for loop and all kinds of fancy business logic for

$contacts['clancy']['home_phone'] = 0123 4567;
vs
$contacts['clancy']['home_phone'] = '';
vs
'home_phone' not set

so one would guess that code would far outweigh any tiny speed gain from dropping the additional items in the array.

on another note; php has been stable and speedy now for a very long time, some bit's like the reflection api could be speeded up a little bit as demand grows, but certainly all scalars and compound types have been tested and optimized to hell and back (afaik).

you can test this all you're self, simply populate an array with say 1000 random other arrays of data with 10 keys each, stick it in a for loop and time several times, then do the same for an array as above but with subarrays of only 5 keys; see if you can spot any significant difference. [then compare to say a single database select, or an execution of a small script.]

another way of putting it; I'm 99% sure that nobodies code is perfectly optimised enough by itself to notice any performance hits from php; quite sure you could make far bigger gains by optimising you're own code first :p

regards! <ramble>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux