views:

120

answers:

7

Hi I know that design-patterns are very useful in creating of big projects. Does anyone have experience in both creating project with normal (OO, procedural ) and using design patterns in respect to performance(speed of execution)? I want to create some big project and I am afraid that using design patterns my scripts would run slower. So What is pefrmance of code with desing paterns compare to normal OO programming?

Greetings

A: 

This depends entirely on what your application is doing and on the details of how you implement the patterns. Design patterns themselves are not really related to performance, but are intended to help you structure your system to aid maintainability.

Besides, performance should not be a concern at this stage; focus on getting the design pinned down first, and if it turns out to be running too slowly, only then should you worry about optimization.

Will Vousden
+11  A: 

Personally,

I'd program it, and then figure out if there are speed problems/bottlenecks.

Only worry about performance when it becomes a problem.

Chacha102
+1: Premature optimization...
S.Lott
+6  A: 

The objective of design patterns is to solve common problems. These problems may include maintainability (which is what it sounds like you're mostly interested in), as well as performance.

Personally, I would favour applying architectural patterns first to make the operations of your application easy to understand. It should then be easier to refactor the existing code to introduce some performance-related patterns, should the performance of your code warrant it.

David Grant
That's hardly true. The "Common Operations Hoist" design pattern is about optimization of loops that have an unchanging, recalculated value in them. I think one can find dozens of code optimization design patterns.
S.Lott
@S.Lott: this better?
David Grant
@David Grant: No, I'd dispute that, also. For example, using the **State** design pattern eliminates a lot of slow if-statements and replaces them with simple (fast) object dereferencing and method invocation.
S.Lott
@S.Lott: Rewritten!
David Grant
+1  A: 

Rarely code complexity is a factor in total execution speed of a PHP application, usually database interaction and network transfer times are much better candidates for slowness.

In any case, develop first and optimize later. You might found out that that kind of optimization is not even necessary.

kemp
+1  A: 

Some of the reasons design patterns are used is to eliminate code duplication and placing the code in the right spot. Both of these factors adds up to a fast application. Individual techniques such as caching and loading-code-only-when-needed could be easier/faster to apply with design patterns.

That said, maintainability will be much more prominent with some kind of thinking behind the coding applied, which will let you as a programmer focus on the real performance issues.

chelmertz
A: 

Well I don't have experience with programming using design patterns (only MVC). It is useful for maintainability, but amount of classes/code is greater compare to OO programming. (that is conclusion from my research ,but not from experience). By desing patterns I mean Factory,Decorator, Singleton etc.

I don't want to be in a situation that my code is well maintained but run slowly. Ex. Many ORM solutions are well maintained but much slower than simple query request coding.

Michael
you might want to edit your question and put this in it.
andyk
+1  A: 

An old adage about database design can be applied here: "Design for normalization first, denormalize for performance later". In this case, design it right the first time, if you find performance bottlenecks, optimize and break elements of your design on a one off basis then. Another issue, get someone using your application before you start optimizing, otherwise, who really cares?

marr75
+1 Normalize until it hurts, then denormalize until it works
Wesley Hill