The document provides coding tips to write efficient code, including considering time and space complexities, understanding the low-level language, following common rules like keeping code short and reusable, using appropriate data structures, and optimizing operations. It suggests avoiding excessive function calls and loops, reusing parameters, and extracting repeated blocks into functions.
2. TIME AND SPACE COMPLEXITIES
Know the space consuming of your code
How often it is called
Code time consuming
AVOID:
For Loops, Calling too much data, Primitive data structures.
3. LOW LEVEL LANGUAGE
Understand the low level language of your coding high level language.
In assembly:
Function has more than 5 passed params is forced to store params in
memory rather than hash.
Jne and je are faster than jle and jge
4. COMMON RULES
The shorter, the merrier! << Lese byte codes
Don’t repeat yourself
Use libraries << Faster algorithms Except you know for sure the library
implementation is not optimized.
Use different data structures.
Don’t traverse one data block more than once in same function unless
necessary.
Know your coding language capabilities.
Don’t pass unneeded params. remember passing struct by value
Don’t call function within a loop.
5. COMMON RULES
Write your code gradually, from bottom to top; most frequent to use first <<
Exceptions are first lines of our services.
Use the fastest shapes of statements: and operation rather than %, or
operation rather than comparting to None then setting.
Reuse local params. Remember registers capacities.
Does the compiler optimize operations: bit-shift of power 2 multiplication?
Multithreading for heavy blocks.
Extract repeated blocks into functions.
BE SURE THAT YOUR CHANGE IN CODE IMPROVED THE PERFORMANCE
INDEED!