Why aren't Ranges Interfaces?

Justin Whear via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 26 12:58:05 PDT 2015


On Fri, 26 Jun 2015 19:26:56 +0000, Jack Stouffer wrote:

> Thanks for the reply! I understand the reasoning now.
> 
> On Friday, 26 June 2015 at 18:46:03 UTC, Adam D. Ruppe wrote:
>> 2) interfaces have an associated runtime cost, which ranges wanted to
>> avoid. They come with hidden function pointers and if you actually use
>> it through them, you can get a performance hit.
> 
> How much of a performance hit are we talking about? Is the difference
> between using an interface and not using one noticeable?

For some real numbers, a while back I wrote up several variations on a 
"big data" type process for a presentation on memory performance and the 
importance of cache hits.  The classic Java-style class-based version ran 
in 4 seconds while the lazy range struct version ran in 0.83 seconds.  
Using LDC to inline (impossible with interfaces) brought the runtime down 
to 0.38 seconds.


More information about the Digitalmars-d-learn mailing list