Inherent code performance advantages of D over C?

Walter Bright newshound2 at digitalmars.com
Fri Dec 6 14:52:49 PST 2013


On 12/6/2013 2:40 PM, bearophile wrote:
> I think in your list you have missed the point 8, that is templates allow for
> data specialization, or for specialization based on compile-time values.
>
> The common example of the first is the C sort() function compared to the type
> specialized one.

That's a good example.


>> 2. D knows when functions are pure. C has to make worst case assumptions.
>
> Perhaps D purity were designed for usefulness, code correctness, etc. but not to
> help compilers. I remember some recent discussions in this newsgroup by
> developers of GDC that explained why the guarantees D offers over C can't lead
> to true improvements in the generated code. If this is true then perhaps D has
> some features that weren't designed in hindsight of what back-ends really need
> to optimize better.

dmd can and does remove multiple calls to strongly pure functions with the same 
arguments.


> There are also situations where D is slower than D: when D can't prove that an
> array will be accessed in bounds [*].

In the cases where D cannot, can C? Nope. C doesn't even know what an array is. 
Can any other language? Nope.


> And when a D compiler because of separate compilation can't de-virtualize a virtual class method call.

Can C devirtualize function calls? Nope.



More information about the Digitalmars-d mailing list