23.11.2010 2:23, bearophile wrote:
Time ago I have found a little C++ program that computes the number of
solutions to the N Queens problem at compile-time using just templates. I have
translated it into CTFE code and I have shown in this newsgroup that if your
purpose is to compute a result at compile-time, then D CTFE allows you to write
much simpler (and faster) code compared to the C++ template mataprogramming.
This time I have translated that C++ code to D code that uses just templates.
This is not idiomatic D code, because for this purpose CTFE is better, but
templates are used in D too, so it may be a performance benchmark for templates
in general.
I am not very good with C++ templates yet, so if you spot an error in my D
translation please tell me that I will redo the timings.
Compilation time: G++ 0.96 seconds, dmd 12.4 seconds.
With N=7 G++ uses about 34 MB RAM, DMD about 130+ MB RAM.
I have used MinGW 4.5.1 and DMD 2.050.
It'd be good if you also posted the machine specs. I ran the benchmark on
Intel i5 750 with 8Gb RAM under Windows7 Pro x64.
I don't have G++ right now, but I tried cl from Visual Studio 2008 and
dmc 8.42n instead
Here are the timings (compiler-version-seconds):
dmd 2.050 2.97958
cl 15.00.30729.01 3.65038
dmc 8.42n 11.6375
So at least on this system dmd doesn't look that bad at all.