Performance tests
From time to time, I wonder which drain "nice" codewriting has on performance.
The Pred(n) vs. n-1 thing:
The classic thing seems to be running loops to n-1, but somehow I grew to appreciate the look of Pred(n) in loop end parameters - as a prefix, its easier to see on wide lines and small screens, for instance.
This needs one billion runs to at least show a difference that could be recognized and is not influenced by the minimum time span of the standard Windows API (you can go more exact if you want, but I did just raise the number of runs). With such a test set that is large enough, the time needed is exactly the same.
My conclusion: keep it as it is - using more Pred(n) as I write now or update old code, but without hurries to port old code over for performance reasons.
The FreeAndNil(o) vs. o.Free thing:
Coding with .Free means there is no dependency to the huge unit SysUtils, and is one call less, which is why I preferred it for quite a while, until I learned the advantages while debugging if destructed objects are set to nil (the Watch would otherwise case AVs, or disturb FastMM). So I went ahead and compared two loops of construction/destruction.
FreeAndNil(o) takes 5.703 seconds, o.Free takes 5.625 seconds. That's a difference of 0.078 seconds (for a 10 million operations loop), or about 1.4%.
While FreeAndNil is slightly smaller, ten million destructions are something that few applications will do, and even if they do, less than a tenth of a second can be spared to make memory leak testing much easier.
