Template performance

Jonathan M Davis jmdavisProg at gmx.com
Tue Nov 23 10:44:46 PST 2010


On Tuesday, November 23, 2010 08:43:20 Steven Schveighoffer wrote:
> 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

There are also definitely memory issues with compiling templates: 
http://d.puremagic.com/issues/show_bug.cgi?id=4984

It's enough, for instance, that you can't use very many arguments to a single 
call to find(), or the compiler will run out of memory. I expect that it plays a 
definite part in the slow template compilation.

- Jonathan M Davis


More information about the Digitalmars-d mailing list