Why is std.algorithm so complicated to use?

Brad Anderson eco at gnuk.net
Tue Jul 10 11:53:37 PDT 2012


On Tue, Jul 10, 2012 at 3:35 AM, Jacob Carlborg <doob at me.com> wrote:

> On 2012-07-10 08:59, Dmitry Olshansky wrote:
>
>  Can you do it in other languages?
>>
>
> Sure, in Ruby, but that only works on arrays:
>
> p [5, 3, 5, 6, 8].uniq.map{ |e| e.to_s }.sort
>
> Prints:
>
> ["3", "5", "6", "8"]
>
> --
> /Jacob Carlborg
>

For what it's worth:

    e = 10_000_000
    a = ((1..e).to_a + (1..e).to_a).sort.uniq.map{ |e| e }

Runs in 21,320 ms on my machine with Ruby 1.9.3 whereas:

    auto end = 10_000_000;
    auto a = chain(iota(1, end), iota(1, end)).array()
                .sort()
                .uniq()
                .map!(n=>n).array();

Runs in 3,057ms with DMD 2.059.  I believe they are largely equivalent but
there is probably room for improvement on both.  I removed to_s/to!string
because I didn't want it allocation bound since we are talking about
algorithm and not the GC or string conversion (with string conversion the
numbers are 28,646ms for Ruby and 14,113ms for D).

Regards,
Brad Anderson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120710/f660413d/attachment.html>


More information about the Digitalmars-d mailing list