Cheatography
https://cheatography.com
Logic
Found |
Stop testing when answer found |
Frequency |
Order tests by frequency in switch and if-else structures |
Switch |
Substitute switch statement for if-else construct |
Lookup Table |
Substitute table lookups for complicated expressions |
Lazy Evaluation |
Only a few entries are ever used. Cache them for further use it may be better to compute values as needed. |
|
|
Loops
Unswitching |
If the decision doesn’t change while looping turn the loop inside out |
Jamming |
Combines two or more loops into one. Reduces loop overhead |
Unrolling |
Replaces a loop with straight-line code. With partial unrolling, two or more cases are handled inside |
Minimize work |
Put calculations that result in a constant before the loop |
Sentinel Values |
Special value that marks the end of an array. Replaces expensive compound tests |
Busy Loop Inside |
Putting the busiest loop on the inside |
|
|
General
Routines - Inline |
Rewrite routines inline |
Routine - Rewrite |
Rewrite expensive system routines |
Data tran – Float/Int |
Replace f.p. numbers with integers |
Data tran – Array Dims |
Reduce array dimensions where possible |
Data tran – Array Refs |
Minimize array references |
Data tran – Supp |
Length index for arrays |
Data tran – Caching |
Save commonly used values, instead of recomputing or rereading them |
Exp - Str redu |
Replace expensive operations with cheaper ones |
Exp - Compile Time |
Initialize at compile time |
Exp - Data Type |
Use the proper data type for constants |
Common Sub-Exp |
Eliminate common subexpressions |
Exp - Precompute |
Better to look up values than to recompute them |
|
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
More Cheat Sheets by Heavenel