views:

34

answers:

1

Now I know there is some related questions on this topic but this is somewhat unique.

I have two array structures :

array(
    [0] => array(
        'stat1' => 50,
        'stat2' => 12,
        'stat3' => 0,
        'country_name' => 'United States'
        ),
    [1] => array(
        'stat1' => 40,
        'stat2' => 38,
        'stat3' => 15,
        'country_name' => 'Ireland'
        ),
    [2] => array(
        'stat1' => 108,
        'stat2' => 0,
        'stat3' => 122,
        'country_name' => 'Autralia'
        )
    )

and the second

array(
    'stat1' => array(
        'countries' => array(
            'United States' => 50,
            'Ireland' => 40,
            'Autralia' => 108,
            )
        )
    ),
'stat2' => array(
        'countries' => array(
            'United States' => 12,
            'Ireland' => 38,
            )
        )
    ),
etc...

The second array can go even to level 4 or 5 if you add the cities of those respective countries. Further to note is that the second array structure will have no 0 data fields (note that in the second one australia is not there because it is 0) but the first structure will have a whole whack of zeros. Also note that the second structure will have duplicates i.e. 'United States'

My question is this: How does these array structures compare when they are json_encode() and used in a POST ajax request? Will the shallow depth array, with it's whack of zeros be faster or will the better structured array be better in terms of size?

A: 

I have done some testing and for a finite dataset the difference in the output data - (I outputted the data into a text file) between the two is insignificant really.

Array structure 1 - All city and country data outputs to 68kb

Array structure 2 - All city and country data outputs to 71kb

So there is a slight difference but it seems that the difference is insignificantly small when taking into account that the data is in JSON format and used in an AJAX request to the google visualization geomap API.

I haven't tested the micro times in loading difference but for a user to look at a loading .gif image for 0.0024microseconds (i'm shooting a random time for the sake of argument) does not make a big dent in usability either way. Thanx all for you comments

etbal