PHP Objects vs Arrays -


I have a large number of PHP objects for a neural network, for which I have to pay attention again and do some math . I was wondering if it would be better to use an associative array on the examples of classes?

I'm working with approximately 3640 objects and around 500 at the top of that time (best) then any micro-optimization is a Does it help in great deal? Essentially $ item ['value'] to $ object-> Value ?

Edit: So they are both the same. But I think the constructor will be a little higher? Either way, I do not think I want to trade in my beautiful sections for dirty arrays:

< In the code of p> based quasal, I ran the next code (5.4.16 Windows 64 bit):

  & lt ;? Php class someclass {public $ aaa; Public $ BBB; Public $ ccc; } Function p ($ i) {echo '& lt; Pre & gt; '; Print_r ($ i); Echo & lt; / Pre & gt; '; } $ T0 = microgram (true); $ ArraysOf = array (); $ Inicio = memory_get_usage (); For ($ i = 0; $ i <1000; $ i ++) {$ z = array}; For ($ j = 0; $ j $ l; 1000; $ j ++) {$ z ['A' '] =' AAA '; $ Z ['BBB'] = 'BBB'; $ Z ['ccc'] = $ z ['AA'] $ Z ['BBB']; $ $ ArraysOf [] = $ z; } $ Fin = memory_get_usage (); Echo '& lt; P & gt; Arrays: '. (Microtom (true) - $ t0). "& Lt; / p & gt;"; Echo & lt; P & gt; Memory: '. ($ Fin- $ inicio). "& Lt; / p & gt;"; P ($ Z); $ T = microtom (true); $ ArraysOf = array (); $ Inicio = memory_get_usage (); ($ I = 0; $ i & lt; 1000; $ i ++) for {$ z = new SomeClass (); ($ Z = 0; $ j & lt; 1000; $ j ++) for ($ z-> aaa = 'aaa'; $ Z- & gt; BBB = 'BBB'; $ Z- & gt; ; Ccc = $ z-> aaa. $ Z-> BBB;} $ arraysOf [] = $ z;} $ Fin = memory_get_usage (); echo '' 

arrays: '. ( Microtom (true) - $ T.). "& Lt; / p & gt;"; echo & lt; p & gt; Memory: '. ($ Fin- $ inicio). "& Lt; / p & gt;" ; P ($ z); $ t = microtom (true); $ arraysOf = array (); $ for Inicio = memory_get_usage (); for ($ i = 0; $ i <1000; $ i ++) { $ Z = new studs for class (); ($ J = 0; $ j & lt; 1000; $ j ++) ($ z-> aaa = 'aaa'; $ Z- & gt; BBB = 'BBB'; $ Z-> Ccc = $ z-> aaa. $ Z-> BBB;} $ ArraysOf [] = $ z;} $ Fin = memory_get_usage (); Echo '' P & gt; ar Rays: '. (Microtom (true) - $ T.). "& Lt; / p & gt; echo & lt; p & gt; Memory:'. ($ Fin- $ inicio)." & Lt; / P & gt; "; P ($ Z);? & Gt;

and I get the next result:

  Arrays: 1.8451430797577 Memory: 460,416 array ([Aaa] = & gt; Aaa [bbb] = & gt; Bbb [ccc] = & gt; Arrays: 1.8294548988342 Memory: 275696 SomeClass object ([aaa] => aaa [bbb] => bbb [ccc] => aaabbb arrays: 2.2577090263367 Memory: 483,648 stdClass object ([aaa] = & Conclusion 
  1. Fasting from the orbit array

    Is (but moderately).

  2. stdClass is bad.
  3. Class uses less memory than arrays. (Approximately 30-40% less!) Ps: As a note, if the class is defined but after members, the use of this class is slow It is more memory

    update

    I used php 5.4 to php 5.5 (5.5.12 x 86 window) to define members. Updated from Arrays: 1.6465699672699 Memory: 460,400 array ([aaa] => aaa [bbb] => bbb [ccc] => aaabbb arrays: 1.8687851428986 Memory: 363,704 SplFixedArray Object ([0] = & gt; aaa [1] = & gt; bbb [2] = & gt; aaabbb arrays: 1.85542511 94 Memory: 275,568 SomeClass object ([aaa] => aaa [bbb] = & Gt; bbb [ccc] = & gt; aaabbb arrays: 2.0101680755615 memory: 483,656 stdClass object ([aaa] => aaa [bbb] = & gt; bbb [ccc] => aaabbb)

    php 5.5

    for
    1. For ARMS, PHP 5.5 is faster than PHP 5.4, it is very similar to the object
    2. < Li> cl Number slow Srli, PHP 5.5 and thanks to the optimization of arrays.
    3. stdClass is bad.
    4. Class still uses less memory than array. (Approximately 30-40% less !!).
    5. SplfixedArray is similar to using the class but it uses more memory.

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -