To test how efficiently the current main D compiler (DMD) supports exceptions (on Windows) I have used this "except" benchmark, code adapted from:
You can find all the code used here in the directory "except" into this zip:
The timings of "except" benchmark, best of 3 (seconds): N = 200_000: C: 0.07 (approx time) Java: 0.41 C++ : 0.54 Psyco: 1.80 Python: 1.90 D: 2.53 SLOW=false D: 4.44 SLOW=true N = 4_000_000: C: 0.36 Java: 5.59 C++: 9.97 Psyco: 29.28 Python: 32.68 D: 48.76 SLOW=false D: 88.45 SLOW=true N = 20_000_000: C: 1.57 C: 1.61 (LLVM-GCC) Java: 27.43 C++: 49.45 CPU: Core 2 at 2 GHz, 2 GB Ram, Windows XP. D code compiled with: DMD v1.041 -O -release -inline C and C++ code compiled with: gcc version 4.3.3-dw2-tdm-1 (GCC) -O3 -s Java: javac 1.6.0_12 java HotSpot build 1.6.0_07-b06 Python: ActivePython 220.127.116.11 (r261:67515, Dec 5 2008, 13:58:38) [MSC v.1500 32 bit (Intel)] on win32 Psyco for Python 2.6, V.1.6.0 final 0
- Having fast exceptions is getting more important, for example it's important to have fast exceptions in Python because there they are sometimes used to control flow too. For example to convert a string to int/float the common Python idiom is to use a try/except.
- As you can see with DMD D exceptions are even slower than Python ones. When N=4_000_000 D exceptions (using writefln) are about 15.8 times slower than Java ones. This isn't good.
- In the D code I don't know why using printf speeds up the code about two times compared to using writefln.
- I'd like to know the timings on Linux with the LDC D compiler.
- The C code isn't fully fair, it uses a lower-level way to implement this program.
- The Java HotSpot VM shows to be quite faster than C++, about 1.8 times when N=20_000_000.
|comments: Leave a comment|