Why is this D code slower than C++?

Bradley Smith digitalmars-com at baysmith.com
Fri Jan 19 22:57:43 PST 2007



Dave wrote:
> Bradley Smith wrote:
>> Thanks for all the suggestions. It helps, but not enough to make the D 
>> code faster than the C++. It is now 2.6 times slower. The render times 
>> are now approx. 13 sec for raytracer_d and approx. 5 sec for 
>> raytracer_cpp.
>>
>> Here are the changes I've made. Attached is the new code.
>>
>>   Call RegisterClass outside of assert. (Broken if -release used)
>>   Apply -release option. (Increases speed in an unknown way)
>>   Converted templates to regular functions. (Templates not being inlined)
> 
> Are you sure? I know templates can be/are inlined and I guess I haven't 
> noticed anywhere they aren't were I'd expect a regularly defined 
> function to be inlined.
> 

You are correct. I have confirmed that the templates and regular 
functions are inlined. However, the way they are inlined appears to 
perform much more moving of data around than manually inlining. Perhaps 
the extra data moving is the cause of the performance degredation by 
using the function or template.

I can also confirm that using inout on the function parameters will 
cause it to not be inlined.

Thanks,
   Bradley


More information about the Digitalmars-d-learn mailing list