Over a million developers have joined DZone.

PHP Speed: Private vs Public Member And Static Methods

· Web Dev Zone

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

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?

Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

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

{{ parent.tldr }}

{{ parent.urlSource.name }}