On 7/21/09 4:52 AM, "Marko Korhonen" <[email protected]> wrote:
> - Is there performance gain or memory savings or something like that?

I don't remember who, but someone on ZFChat had recommended using Factory
for zend_db_table objects to give a performance boost on the application.
After reading this thread, we ran a few tests to see what the actual
performance boost is and it does seem significant.

Here is what we are using for our Factory:
http://pastie.org/553707

Here's the code:
Singleton: http://pastie.org/553697
Non-Singleton:  http://pastie.org/553702

And here's the test results:
Singleton:    0m2.163s
Non-Singleton:    0m15.708s

That's a performance boost of 7X using a singleton versus not using a
singleton.

There are times where singletons are beneficial.  After all, they are used
by ZF.

It also seems like it's easy to add a method to reset the instance in the
factory, which you'll see in the Factory code listed above.

Do you think is a good example of when to use singleton's?

Does this seem to still go against best practices?  I'm trying to get a
better understanding of why more experienced programmers don't use them.

Matthew, could you describe in more detail the problems you were running
into with Unit Testing?

Anything else we could be overlooking?

-Michael

Reply via email to