What's better at freeing memory with PHP: unset() or $var = null

前端 未结 13 2001
陌清茗
陌清茗 2020-11-22 08:57

I realise the second one avoids the overhead of a function call (update, is actually a language construct), but it would be interesting to know if one is be

13条回答
  •  难免孤独
    2020-11-22 09:34

    
    

    Per that it seems like "= null" is faster.

    PHP 5.4 results:

    • took 0.88389301300049 seconds
    • took 2.1757180690765 seconds

    PHP 5.3 results:

    • took 1.7235369682312 seconds
    • took 2.9490959644318 seconds

    PHP 5.2 results:

    • took 3.0069220066071 seconds
    • took 4.7002630233765 seconds

    PHP 5.1 results:

    • took 2.6272349357605 seconds
    • took 5.0403649806976 seconds

    Things start to look different with PHP 5.0 and 4.4.

    5.0:

    • took 10.038941144943 seconds
    • took 7.0874409675598 seconds

    4.4:

    • took 7.5352551937103 seconds
    • took 6.6245851516724 seconds

    Keep in mind microtime(true) doesn't work in PHP 4.4 so I had to use the microtime_float example given in php.net/microtime / Example #1.

提交回复
热议问题