Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance of Singleton Class Instance Method vs. Static Class Method in PHP?

I'm interested in objective analysis of which is more performant; calling instance methods of a singleton class or methods of a static class. I've already seen this so I'm not looking for a discussion about the difference between the two or a discussion of which is "better." I'm only interested in relative performance between the two. Thanks in advance.

-Mike

like image 213
MikeSchinkel Avatar asked Aug 05 '10 19:08

MikeSchinkel


2 Answers

Check this chart :)

alt text

grabbed from this article

like image 198
Andreas Linden Avatar answered Sep 20 '22 09:09

Andreas Linden


Unless you're calling them in a tight loop (meaning no other significant code, where the overhead of the call is significant) thousands or hundreds of thousands of times, don't worry about it. The difference is likely going to be under a microsecond, so it's not worth fretting over. Simply make the best architectural choice...

Premature optimization is the root of all evil...

Edit: To all the downvoters, here's a blog post that I wrote that describes why performance comparisons like this are all but useless.

like image 32
ircmaxell Avatar answered Sep 20 '22 09:09

ircmaxell