Fine-Tuning the Code
I have stated repeatedly that the best way to improve code speed is to change the algorithm. Sometimes, however, this is just not possible because you already use the best possible algorithm. It may also be completely impractical, as changing the algorithm may require rewriting a large part of the program.
If this is the case and the code is still not running quickly enough, we have multiple available options. We can start optimizing the program, by which I mean that we can start changing small parts of the program and replacing them with faster code. This is the topic of this chapter.
Another option is to rewrite a part of the program in an assembler. Delphi offers quite decent support for this, and we’ll look into that possibility near the end of this chapter. We can also find a library that solves our problem. It could be written in an assembler or created by a compiler that produces faster code than Delphi – usually, we don’t care...