Is metaprogramming useful?
Sean Kelly
sean at f4.ca
Tue Nov 28 09:14:22 PST 2006
Just a few corrections, as I was still waking up when I wrote this.
Sean Kelly wrote:
> Frank Benoit (keinfarbton) wrote:
>>
>> 1.) Is metaprogramming really useful or only kind of hype?
>
> In-language code generation has an advantage over using a standalone
> preprocessor to perform the same task. And generated code has the
> potential to contain fewer bugs than hand-written code, as well as
> reduce coding time for a project. Finally, template code in general
> combined with common optimizer techniques can result in extremely fast
> code because it is essentially equivalent to hand-optimized code in many
> cases.
Equivalent to or better than. Inlining is a huge part of why template
code is as fast as it is, and even hand tuning typically results in
little manually inlined code--it's too difficult to maintain.
> How fast? Bjarne did a presentation at SDWest regarding some
> real-world applications where C++ was shown to outperform hand-tuned C
> and even FORTRAN by an order of magnitude for numeric calculations, and
> the reason was entirely attributed to the extensive use of template
> code.
I believe it actually outperformed hand-tuned C by an order of magnitude
and FORTRAN by a smaller margin, but it was still faster. Bjarne
attributed the results to templates, but inlining obviously played a
huge part.
Sean
More information about the Digitalmars-d
mailing list