开发者

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.

  1. top command to see cpu's usage
  2. free command to see memory usage
  3. add timing information to the code
  4. print progress statements in the code
  5. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜