官术网_书友最值得收藏!

Don't guess, measure!

There is only one way to get a good picture about the fast and slow parts of a program—by measuring it. We can do it manually, by inserting time-measuring calls in the code, or we can use specialized tools. We have a name for measuring—profiling—and we call specialized tools for measuring profilers.

In the rest of this chapter, we'll look at different techniques of measuring the execution speed. First we will measure the now familiar program, SlowCode, with a simple software stopwatch and then we'll look at a few open source and commercial profilers.

Before we start, I'd like to point out a few basic rules that apply to all profiling techniques:

  • Always profile without the debugger. The debugger will slow the execution in unexpected places and that will skew the results. If you are starting your program from the Delphi IDE, just press Ctrl+Shift+F9 instead of F9.
  • Try not to do anything else on the computer while profiling. Other programs will take the CPU away from the measured program which will make it run slower.
  • Take care that the program doesn't wait for user action (data entry, button click) while profiling. This will completely skew the report.
  • Repeat the tests a few times. Execution times will differ because Windows (and any other OS that Delphi supports) will always execute other tasks besides running your program.
  • All the above especially holds for multithreaded programs, which is an area explored in Chapters 5 to 7.
主站蜘蛛池模板: 巴林左旗| 中超| 通榆县| 外汇| 应用必备| 宝丰县| 通山县| 县级市| 廉江市| 新河县| 五家渠市| 太谷县| 铜山县| 罗山县| 鹿邑县| 峨眉山市| 贺州市| 盐津县| 香河县| 闻喜县| 澄迈县| 原阳县| 依兰县| 商洛市| 延长县| 巴南区| 合水县| 略阳县| 望江县| 新乡县| 辛集市| 东阿县| 鹤山市| 元氏县| 凤山市| 泽库县| 阿坝县| 呼和浩特市| 乌兰察布市| 佛学| 康平县|