APPENDIX C Optimization and Performance

You might be tempted to use all sorts of clever techniques to optimize the code. However, this optimization comes at a penalty.

Rob Pike provides these comments on program complexity, https://www.lysator.liu.se/c/pikestyle.html, Notes on Programming in C.

"Most programs are too complicated - that is, more complex than they need to be to solve their problems efficiently . . . But programs are often complicated at the microscopic level . . ."

The following are also condensed from Mr. Pike's 1989 Notes on Programming in C

Rule 1. Don't guess at optimization

  • Prove the bottleneck location, then put in a speed hack.

Rule 2. Measure before tuning for speed

  • Be judicious. Only tune for speed if absolutely necessary.

Rule 3. Use simple algorithms

  • Fancy algorithms are slow.

Rule 4. Use simple data structures.

Pike believes that these data structures are almost always enough:

  • array
  • linked list
  • hash table
  • binary tree

Rule 5. Data structures are central to programming; algorithms are not.