I could point out that there is defragging and optimising and deep optimising. And there are an embarrasment of defraggers available to download - mostly free.
Defragging alone just ensures every file is contiguous on disk, but still leaves lots of 'empty' portions of the disk which subsequently cause fragmentation to happen faster in future. This form of defragmentation can indeed be done in seconds. Optimisation, on the other hand, tries to eliminate the 'empty' portions. This requires massive amouonts of file movement and takes, well, hours sometimes. Then there is 'deep' optimising, which can mean various things, such as taking account of frequency of access AND frequency of re-writing to enable the fastest reading parts of the disk to contain those files which are frequently read, but hardly ever written to.
Oh, you could write a book about deframenting ! Some people have.....
Over the years, things have changed a lot, and in my view, defragmentation is just very rarely needed today, and can indeed, be a dangerous thing to do on a continuous basis - you are exercising the drive mechanicals a lot, and unnecessarily so. It must surely reduce the life of the drive.
The time when defragmentation was important was when drives were small, got full quickly, and when large files (music or videos) were a substantial fraction of the drive space. Under those conditions - which ceased 5-10 years ago - a heavily fragmented drive could slow your system, and even cause it to crash.