17.10 Case Study: Inline Functions Versus Normal Functions
I once worked on writing a word-processing program for a large
computer manufacturer. We had a function next_char
that was used to get the next character from the current file. It was
used in thousands of places throughout the program. When we first
tested the program with next_char written as a
function, the program was unacceptably slow. Analyzing our program,
we found that 90 percent of the time was spent in
next_char. So we changed it to an inline function.
The speed doubled; however, our code size went up 40 percent and
required a memory expansion card to work. So the speed was all right,
but the size was unacceptable. We finally had to write the routine as
a function in hand-optimized assembly language to get both the size
and the speed to acceptable levels.
|