www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.ide
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript
electronics




digitalmars.D.bugs - [Issue 2008] New: Poor optimization of functions with ref parameters

↑ ↓ ← d-bugmail puremagic.com writes:
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 digitalmars.com
        ReportedBy: aarti 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);
}

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


-- 
Apr 18 2008
↑ ↓ → d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2008





------- Comment #1 from wbaxter gmail.com  2008-04-18 18:22 -------
I believe the problem is that ref parameters disable inlining in DMD.  Or so I
think I heard somewhere before.


-- 
Apr 18 2008