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

Add user login and MFA to your next project in minutes. Create a free Okta developer account, drop in one of our SDKs to your application and get back to building.

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?

Launch your application faster with Okta’s user management API. Register today for the free forever developer edition!

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}