Denis Koroskin wrote:
On Sat, 14 Feb 2009 21:38:19 +0300, Andrei Alexandrescu <seewebsiteforem...@erdani.org> wrote:
For 20000 evaluations over a 100000-integers array, reduce!(min), reduce!("b > a ? b : a"), and handMax all finished within 3.4 to 3.5 seconds on my machine. The "normal" version took 11.6 seconds to complete. Trials with various sizes reveal a similar pattern throughout: pass-by-delegate is way behind the others, which work about as fast.

This means that, had std.algorithm taken the "normal" route, it would have been plenty useless for any serious needs. Not taking the "normal" route means that its abstractions rival hand-tuned code so I can use them without worrying they will come unglued when shown a real challenge.

So, to paraphrase the ugly guy in "The Good, The Bad, and The Ugly": If you want to shoot, shoot, don't troll.


Andrei

Did you try passing a comparator (C++ way to do things)? It should be pretty fast, to.

Is this what you meant?

struct StructMax
{
    static uint opCall(uint a, uint b)
    {
        return b > a ? b : a;
    }
}

uint reduceStruct(uint[] x, StructMax s)
{
    invariant n = x.length;
    uint m = x[0];
    for (uint i = 1; i < n; ++i) {
        m = s(m, x[i]);
    }
    return m;
}

I did, and as expected the running time is similar to the other fast approaches. Removing "static" does not affect the timings sensibly.


Andrei

Reply via email to