What are some of the common performance issues, irrespective of programming language?
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 开发者_StackOverflow社区improve the algorithm
What do you do, if your code is running very slow.
1) with a profiler, spot the slowest part of your code
2) once you've found them, think of a way to improve them
step 2 is the most difficult. You could need some small changes or rewrite everything
Use a Profiler. The location of resource bottlenecks can be non-intuitive.
Well, yes, profile, but don't use just any old profiler.
You need to look at lines of code that are on the stack a good percent of the time, because that is how much you could potentially save by optimizing them.
To find them, you should use a profiler that
- takes wall-clock-time stack samples (during I/O as well as CPU time),
- when you want them (when it's being slow, not all the time),
- and reports by line of code (not just by function/method)
- the percent of samples containing that line (not count, not self time, not average time - percent).
A good one is Zoom.
Another very simple method is random-pausing.
精彩评论