Why is D slower than LuaJIT?

spir denis.spir at gmail.com
Thu Dec 23 04:22:20 PST 2010


On Wed, 22 Dec 2010 20:16:45 -0600
Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:

> Thanks for posting the numbers. That's a long time, particularly 
> considering that the two map instances don't do anything. So the bulk of 
> the computation is:
> 
> auto L = iota(0.0, 10000000.0);
> auto V = reduce!"a + b"(L3);
> 
> There is one inherent problem that affects the speed of iota: in iota, 
> the value at position i is computed as 0.0 + i * step, where step is 
> computed from the limits. That's one addition and a multiplication for 
> each pass through iota. Given that the actual workload of the loop is 
> only one addition, we are doing a lot more work. I suspect that that's 
> the main issue there.
> 
> The reason for which iota does that instead of the simpler increment is 
> that iota must iterate the same values forward and backward. Using ++ 
> may interact with floating-point vagaries, so the code is currently 
> conservative.

There is a point I don't understand here: Iota is a range-struct template, with
    void popFront()
    {
        current += step;
    }
So, how does the computation of an arbitrary element at a given index affect looping speed? For mappings (and any kind of traversal, indeed), there should be an addition per element. Else, why define a range interface at all? What do I miss?

Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d mailing list