通常,代码的性能取决于相对较小的部分(数据结构、函数,甚至单个循环),因此它无论如何都不属于设计模式的范围。将 C 中的直接函数更改为汇编中的超级优化版本可能不会改变整个类的行为方式。
On a more serious note, design patterns will probably reduce performance. From my experience, the usage of design patterns gives cleaner, more maintainable code. Should you need to optimize anything, you would probably need to de-design pattern the code.
Often performance of code is dependent on a relatively small piece (a data structure, a function, or even a single loop), so it doesn't go into the scope of design patterns any way. Changing a straight forward function in C to a super optimized version in assembly probably won't change the way the entire class behaves.
The object pool pattern is a software creational design pattern that uses a set of initialized objects kept ready to use – a "pool" – rather than allocating and destroying them on demand.
Object pools are primarily used for performance: in some circumstances, object pools significantly improve performance.
发布评论
评论(5)
更严重的是,设计模式可能会降低性能。根据我的经验,设计模式的使用可以提供更清晰、更易于维护的代码。如果您需要优化任何内容,您可能需要对代码进行反设计模式。
通常,代码的性能取决于相对较小的部分(数据结构、函数,甚至单个循环),因此它无论如何都不属于设计模式的范围。将 C 中的直接函数更改为汇编中的超级优化版本可能不会改变整个类的行为方式。
On a more serious note, design patterns will probably reduce performance. From my experience, the usage of design patterns gives cleaner, more maintainable code. Should you need to optimize anything, you would probably need to de-design pattern the code.
Often performance of code is dependent on a relatively small piece (a data structure, a function, or even a single loop), so it doesn't go into the scope of design patterns any way. Changing a straight forward function in C to a super optimized version in assembly probably won't change the way the entire class behaves.
Flyweight 减少了内存消耗。
代理模式可用于速度优化。
桥接模式可以动态改变抽象的实现——总是选择
最有效率的一个。
Flyweight reduces memory consumption.
The Proxy pattern can be used for speed optimization.
The Bridge pattern can change the implementation of an abstraction on the fly - always picking
the most efficient one.
对象池模式
Object Pool Pattern
没有什么比这更好的了。设计模式用于使您的
开发
和维护
更容易。大多数设计模式用于
There is nothing like that.Design patterns are used to make your
development
andmaintance
easier.mostly design patterns are used for
可能是“不要做傻事”的模式。如果遵循 T 恤,您会发现它击败了:
放手
Probably the "don't-do-stupid-tings" pattern. If followed to the tee, you'll find it beats:
Hands down