Here some general tips for getting better code are presented. They are
mainly concerned with coding style.
Find a better algorithm. No matter how muck you and the compiler
tweak the code, a quicksort will (almost) always outperform a bubble
sort, for example.
Use variables of the native size of the processor you're writing
for. For the 80x86 and compatibles, this is 32 bit, so you're best of
using longint and cardinal variables.
Turn on the optimizer.
If you are allocating and disposing a lot of small memory blocks,
check out the heapblocks variable. (Reference guide\)
Profile your code (see the -pg switch) to find out where the
bottlenecks are. If you want, you can rewrite those parts in assembler.
You can take the code generated by the compiler as a starting point. When
given the -a command-line switch, the compiler will not erase the
assembler file at the end of the assembly process, so you can study the
assembler file.
Note: code blocks which contain an assembler block, are not processed
at all by the optimizer at this time.