Port a benchmark to D?

bearophile bearophileHUGS at lycos.com
Fri Jun 3 15:48:42 PDT 2011


Andrei:

> Does anyone have the time and inclination to port the benchmark so we can take a look?

My modified C++0x code:
http://codepad.org/iBwINTkJ

First D2 translation that seems to work:
http://codepad.org/sEEFNlAd

Notes on the translation:
- The program crashes with zero error messages if you don't increase the stack. Time ago I have written an enhancement request on this:
http://d.puremagic.com/issues/show_bug.cgi?id=6088
- The final print of the "." done using write() doesn't perform the fflush. So after few tries I have used printf. I have not found a good way to flush. Suggestions welcome.
- The C++ code uses classes, but they are often more like D structs. In the first D version to keep things simple I have used final classes everywhere. I will profile the code and I will create a more efficient version that uses structs where needed.
- I have had to track down a null reference error (caused by the nodes array, that contains just references in the first D version). Nonnullable type modifiers avoids similar bugs at compile-time.
- The C++ code is 25 KB, the D code (first version is 21 KB), the C++ code uses about 100 MB at runtime, while the D code uses about 160 MB.
- The C++ loops to iterate on collections is many times worse than the D foreach.
- In the main() of C++ code, there is a LoopStructureGraph lsg that shadows another one, I've replaced it with a lsg2 in both D and C++ code.
- In the C++ code I have used a std::unordered_map to implement BasicBlockMap, because it's significantly faster. So now the code is C++0x.
- The method names start with uppercase, I'd like to change this in a second D version.
- No linked lists or sorted dictionaries seem needed in this program. But I have felt a bit of need of a set data structure in D (I have used an AA with bool values).

Despite there are some associative arrays of SimpleLoop and BasicBlock objects, I think their classes don't need a hash function and opEquals.

Bye,
bearophile


More information about the Digitalmars-d mailing list