When you open or save a fragmented file that is larger than 20 MB the OS tries to make it contiguous, but that's about all. No defragging of unused space, no relocation of files to optimize startup times or anything like that.
EDIT--- Made a couple of mistakes here, only files SMALLER than 20 MB are defragmented this way. Also, some relocation of files do occur on journalled disks (journalling is on by default for disks formatted in 10.2 or later). Files that are never written to, only read from, will be relocated to a "hot area" of the disk, if they are read often enough. ---/EDIT
The optimizing that occurs at the end of installations has to do with prebinding, most applications use several files (reminiscent to Windows DLL concept), and the system wants to know which ones to use at startup. That information is stored in a "database" of sorts, to speed up application launches. The optimisation is merely an update of that database, no files are moved in this process.
There are defragmentation applications available, and if you often run out of space, so you are deleting files to install or save new ones it might be a good idea to get one of those apps.
Me, I've never bothered, and I've been running the oldest of my systems for three years since I last formatted the drive (right after I bought it). I have no idea how fragmented my drive is, but it doesn't run slower than the second oldest that I reformatted last week (same CPU and disk combination). My guess is that you will loose all the time you gain from a defragmented disk during defragmentation, i.e. it will take as long or longer to defragment your disk as the time you are likely to save from faster disk operations until the next defragmentation session...
In short: don't bother.