<div>2010/11/23 Stanislav Blinov <span dir="ltr"><<a href="mailto:blinov@loniir.ru">blinov@loniir.ru</a>></span></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">23.11.2010 2:23, bearophile wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.<br>

<br>
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.<br>

<br>
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.<br>
<br>
Compilation time: G++ 0.96 seconds, dmd 12.4 seconds.<br>
<br>
With N=7 G++ uses about 34 MB RAM, DMD about 130+ MB RAM.<br>
<br>
I have used MinGW 4.5.1 and DMD 2.050.<br>
<br>
</blockquote>
<br></div>
It'd be good if you also posted the machine specs. I ran the benchmark on<br>
Intel i5 750 with 8Gb RAM under Windows7 Pro x64.<br>
<br>
I don't have G++ right now, but I tried cl from Visual Studio 2008 and dmc 8.42n instead<br>
<br>
Here are the timings (compiler-version-seconds):<br>
<br>
dmd 2.050            2.97958<br>
cl  15.00.30729.01   3.65038<br>
dmc 8.42n            11.6375<br>
<br>
So at least on this system dmd doesn't look that bad at all.<br>
</blockquote></div><br><div>I'm getting:</div><div>MinGW G++ (source code modified): <span class="Apple-tab-span" style="white-space: pre; "> </span>744 miliseconds</div><div>MinGW G++ (usual version):<span class="Apple-tab-span" style="white-space: pre; "> </span> <span class="Apple-tab-span" style="white-space: pre; ">        </span>924 miliseconds</div>
<div>Dmd:<span class="Apple-tab-span" style="white-space: pre; ">       </span>   <span class="Apple-tab-span" style="white-space: pre; ">                              </span><span class="Apple-tab-span" style="white-space: pre; "> </span><span class="Apple-tab-span" style="white-space: pre; "> </span>4275 miliseconds</div>
<div><span class="Apple-tab-span" style="white-space: pre; "></span></div><div><span class="Apple-tab-span" style="white-space: pre; "></span></div>(i7 720QM, 4GB ram)<br><br>-- <br>// Yours sincerely<br>// Emil 'Skeen' Madsen<br>