[Issue 10287] New: std.random.uniform is very slow with dmd

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 6 17:39:55 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10287

           Summary: std.random.uniform is very slow with dmd
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-06-06 17:39:54 PDT ---
This program runs about 6 times faster compiled with ldc2 compared to dmd (I
run it with 100000000 command line argument):


import core.stdc.stdio, std.random, std.conv;

void main(in string[] args) {
    immutable uint N = (args.length == 2) ?
                       args[1].to!uint :
                       1_000;
    auto rng = Xorshift(0);

    uint total = 0;
    for (uint i = 0; i < N; i++)
        total += uniform(0, 10, rng);

    printf("%u\n", total);
}



If I replace this line:
total += uniform(0, 10, rng);

with:
total += rng.front;  rng.popFront;

Then the code compiled with ldc2 is only about 30% faster.


dmd 2.064alpha, -O -release -inline -noboundscheck.

Ldc2 V. 0.11.0, based on DMD v2.062 and LLVM 3.3svn, -O5 -release
-profile-verifier-noassert.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list