Normally, if my code has any performance issue, I will follow the below steps to understand the cause.
- top command to see cpu's usage
- free command to see memory usage
- add timing information to the code
- print progress statements in the code
- understand and improve the algorithm
What do you do, if your code is running very slow.