Template performance

Steven Schveighoffer schveiguy at yahoo.com
Tue Nov 23 08:43:20 PST 2010


On Mon, 22 Nov 2010 18:23:37 -0500, bearophile <bearophileHUGS at lycos.com>  
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.

This might be due to a bug I reported how DMD is very slow when dealing  
with lots of templates.

See http://d.puremagic.com/issues/show_bug.cgi?id=4900


More information about the Digitalmars-d mailing list