Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

PHP Speed: Private vs Public Member And Static Methods

DZone's Guide to

PHP Speed: Private vs Public Member And Static Methods

· Web Dev Zone ·
Free Resource

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

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:

  Time(sec) RAM(Mb)
Private 1,53 36
Public 1,27 36
Static 1,47 0,15

*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?

Deploying code to production can be filled with uncertainty. Reduce the risks, and deploy earlier and more often. Download this free guide to learn more. Brought to you in partnership with Rollbar.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}