The questions that every developer should have in mind while optimizing their code are as follows:
- What number of function calls is your code making?
- Are there redundant calls?
- How much memory is the code using?
- Are there memory leaks?
- Where are the bottlenecks?
The first four questions are mostly answered by profiler tools. You are advised to learn at least about one profiling tool. Profiling tools will not be covered in this chapter. In most cases, it is suggested to first try to optimize function calls and memory usage before diving into lower-level approaches such as Cython or assembly languages (in C-derived languages).
Once the bottlenecks have been identified and all the issues with algorithms and logic have been tackled, a Python developer can dive into the world of Cython to get extra speed out of your application.