totallyNotLizards
totallyNotLizards

Reputation: 8549

Does the number of functions in my PHP class affect performance?

I'm working on a class in PHP which is now over 4800+ lines long (around 202KB currently) - it contains a large collection of functions. It's almost a framework but not generic (or advanced) enough to be worthy of the term.

There is a __construct() function which connects to a database and runs one select query, and no public functions.

I simply include the file in the pages I need to use it on, and call it like so:

<?php $myFramework = new MyFramework(); ?>

Here's my question - does the amount of functions in my class have any impact on performance over and above whatever impact the __construct() function has when it runs?

Does including a 202KB file slow down my web app in any way, such that it might be advisable to split my functions into smaller files?

Upvotes: 2

Views: 572

Answers (3)

Frankie
Frankie

Reputation: 25165

There is no way to tell...

May sound a bit vague but it's so generic the only way you can be sure is to measure it.

Then again, if you are worried about performance you'll probably be implementing an opcode cache like APC. As soon as you do that the class is cached and parsing all the code will be irrelevant.

As a rule of thumb DB queries are almost always the first to be optimized and the bottleneck but, when in doubt, measure.

Upvotes: 2

Bogdan Burym
Bogdan Burym

Reputation: 5512

Only in you case, but not generally:

If talk about speed, splitting your functions into smaller files will increase count of includes and slow your application down much greater.
As you say, your methods are logically dealed, so you may keep your code as it is.

Upvotes: 4

Damien Overeem
Damien Overeem

Reputation: 4529

It pretty much depends on the fact if every request requires all that code. If not, you are loading way more data per request then necessary.

Basically: if all the code is necessary for each request, putting it all in one file is the fastest. If it is not, splitting it up is much faster.

Upvotes: 1

Related Questions