Code Tuning
Code Tuning
Code Tuning
Code tuning is one way of improving a program’s performance.
The problem with code tuning is that efficient code isn’t necessarily
“better” code.
The Pareto Principle
Also known as the 80/20 rule
• You can get 80 percent of the result with 20 percent of the effort.
The principle applies to a lot of areas other than programming, but it
definitely applies to program optimization.
Barry Boehm reports that 20 percent of a program’s routines
consume 80 percent of its execution time
Introduction to Code Tuning
Knuth used a line-count profiler to discover this surprising relationship, and the
implications for optimization are clear.
You should measure the code to find the hot spots and then put your resources
into optimizing the few percent that are used the most.
Knuth profiled his line-count program and found that it was spending half its
execution time in two loops. He changed a few lines of code and doubled the
speed of the profiler in less than an hour.
Introduction to Code Tuning
Jon Bentley describes a case in which a thousand-line program spent
80 percent of its time in a five-line square-root routine. By tripling
the speed of the square root routine, he doubled the speed of the
program
Code Tuning
Here are some common misapprehensions about code tuning