[Issue 2008] New: Poor optimization of functions with ref parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 18 14:18:01 PDT 2008


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

           Summary: Poor optimization of functions with ref parameters
           Product: D
           Version: 1.028
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: aarti at interia.pl


Functions with ref parameters can be up to 2x slower than functions which
parameters are not passed by reference. It is especially visible for programs
which are compiled with all optimizations on:
-O
-inline
-release

Test program:
------------------------

char peek_ref(ref char[] a) {
    return a[0];
}

char peek_noref(char[] a) {
    return a[0];
}


ulong rdtsc() {
    asm {
        naked;
        rdtsc;
        ret;
    }
}

void main() {
    char[] tst = "test string";
    char c;
    long starttime;

    writef("Direct: ");
    starttime = rdtsc;
    for(int i=0; i<1000; i++)
        c = tst[0];
    writefln(c, " - time: ", rdtsc - starttime);

    writef("With ref: ");
    starttime = rdtsc;
    for(int i=0; i<1000; i++)
        c = tst.peek_ref();
    writefln(c, " - time: ", rdtsc - starttime);

    writef("Without ref: ");
    starttime = rdtsc;
    for(int i=0; i<1000; i++)
        c = tst.peek_noref();
    writefln(c, " - time: ", rdtsc - starttime);
}

----------------------


-- 



More information about the Digitalmars-d-bugs mailing list