Update
This commit is contained in:
parent
91a4ce4727
commit
810a5262e4
8 changed files with 47 additions and 39 deletions
|
@ -1,8 +1,12 @@
|
|||
# Optimization
|
||||
|
||||
Optimization means making a program more efficient in terms of consumption of some computing resource or by any similar metric, commonly aiming for greater execution speed or lower memory usage (but also e.g. lower power consumption, lower network usage etc.) while preserving how the program functions externally. Unlike [refactoring](refactoring.md), which aims primarily for a better readability of source code, optimization changes the inner behavior of the executed program to a more optimal one.
|
||||
Optimization means making a program more efficient in terms of consumption of some computing resource or by any similar metric, commonly aiming for greater execution speed or lower memory usage (but also e.g. lower power consumption, lower network usage etc.) while preserving how the program functions externally; this can be done manually (by rewriting parts of your program) or automatically (typically by [compiler](compiler.md) when it's translating your program). Unlike [refactoring](refactoring.md), which aims primarily for a better readability of source code, optimization changes the inner behavior of the executed program to a more optimal one. Apart from optimizing programs/[algorithms](algorithm.md) we may also more widely talk about optimizing e.g. [data structures](data_structure.md), file formats, [hardware](hardware.md), [protocol](protocol.md) and so on.
|
||||
|
||||
## General Tips'N'Tricks
|
||||
## Manual Optimization
|
||||
|
||||
These are optimizations you do yourself by writing better code.
|
||||
|
||||
### General Tips'N'Tricks
|
||||
|
||||
These are mainly for [C](c.md), but may be usable in other languages as well.
|
||||
|
||||
|
@ -57,7 +61,7 @@ These are mainly for [C](c.md), but may be usable in other languages as well.
|
|||
- **Smaller code may also be faster** as it allows to fit more instructions into [cache](cache.md).
|
||||
- Do not optimize everything and for any cost: optimization often makes the code more cryptic, it may [bloat](bloat.md) it, bring in more bugs etc. Only optimize if it is worth the prize. { from *Game Programming Gurus* -drummyfish }
|
||||
|
||||
## When To Actually Optimize?
|
||||
### When To Actually Optimize?
|
||||
|
||||
Nubs often ask this and this can also be a very nontrivial question. Generally fine, sophisticated optimization should come as one of the last steps in development, when you actually have a working thing. These are optimizations requiring significant energy/time to implement -- you don't want to spend resources on this at the stage when they may well be dropped in the end, or they won't matter because they'll be outside the bottleneck. However there are two "exceptions".
|
||||
|
||||
|
@ -65,6 +69,10 @@ The highest-level optimization is done as part of the initial design of the prog
|
|||
|
||||
Another kind of optimization done during development is just automatically writing good code, i.e. being familiar with specific patterns and using them without much thought. For example if you're computing some value inside a loop and this value doesn't change between iterations, you just automatically put computation of that value **before** the loop. Without this you'd simply end up with a shitty code that would have to be rewritten line by line at the end. Yes, compilers can often do this simple kind of optimization for you, but you don't want to rely on it.
|
||||
|
||||
## Automatic Optimization
|
||||
|
||||
TODO
|
||||
|
||||
## See Also
|
||||
|
||||
- [refactoring](refactoring.md)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue