PHP Speed: Private vs Public Member And Static Methods
Join the DZone community and get the full member experience.Join For Free
I did some speed testing for my PHP framework(still alpha) and I discovered some surprising results.
For the test I have PHP 5.2.3 and MySQL 5.0.41 with 100000 records varchar(250).Tested with Xdebug.
I wrote 3 classes one with Public Members(Public Methods) , Private Members(Public Methods) and Public Static Members(Public Static Members) with same structure.
I tested the time and ram usage:
*Lower is better.
For just declaring Public over Private Members I gain 20% of speed and RAM consumption remains the same(both methods are public).
And the thing that surprised me the most is RAM consumption of static members with static methods just 0,15 MB!! Wow! Then I tested from other online libraries with private or public(methods and members) and the RAM consummation was always very high.
Do you have similar experience?
Opinions expressed by DZone contributors are their own.