“Don’t get hung up on optimizing compilers or assembly language – the best optimizer is between your ears” – Michael Abrash, The Zen of Code Optimization
- To see if the theory that optimization is mostly the responsibility of the programmer can be easily supported.
- To see if there might be some coding techniques that will produce good cross-platform code, or if the ‘best’ coding practices are to target a particular platform.
Six individuals rose to the challenge and submitted their entries. Though most submitted C-based solutions, one submitted a Delphi solution, and one even submitted an all-assembler solution. The entrants submitted source code, so I compiled the C solutions myself with VC7, using the same flags, to make sure they were all on an even footing and test theory #1 above. All but one submitted an executable, which I ran because either I had no way to compile the code (Delphi and assembler based) or I figured it would provide some insight into the differences between various compilers. I also ran the original Delphi executable from the referenced website, and compiled the original C version myself with VC7 using the same flags as the other submissions, just as a reference point.
One problem encountered during testing was that the submitted assembler executable would not function with the timer routine, because it did not recognize the parameters being passed. This forced me to run from the command line, and use the system clock as the timer (by setting the prompt to a timestamp). To ensure that this did not introduce a large difference between what the timer program reported, I also ran several other executables this way. The main problem is that the command prompt timestamp only displays to the microsecond, so it is rounded off a bit – but was generally within a few tens of milliseconds of what the timer reported. Close enough for this test.
Three platforms (PIII CuMine, P4 Northwood and Athlon XP) were set up in order to test theory number 2. All shared the same hard drive (IBM 45GB), and video card (Matrox G550). I intentionally left the processors at different speeds to help readers avoid the temptation of comparing the processors instead of the code. Some may question the choice of speeds, but it was actually the default speeds that each started with after resetting the BIOS (the Athlon and PIII were unlocked). The compiler used was VC7 .NET, with the following command line compile options:
/O2 /Ot /G6 /D “WIN32” /D “NDEBUG” /D “_CONSOLE” /D “_MBCS” /FD /ML /Fo”Release/” /Fd”Release/vc70.pdb” /W3 /nologo /c /TC
For those interested in seeing the actual source code for all of these submissions, they have been included as appendices to this article.
Discuss (16 comments)