[Bug 73] New: Functions used to initialize variables are not inlined.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 24 17:54:16 PST 2006


http://d.puremagic.com/bugzilla/show_bug.cgi?id=73

           Summary: Functions used to initialize variables are not inlined.
           Product: D
           Version: 0.150
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: godaves at yahoo.com


/*
   Compile with -O -inline -release
   This program compares performance of 2 loops, one initializing a
    scope local variable w/ a function and the other not.
   The function used as an initializer is not inlined.
   There is about a 11x difference on my system.
*/

import std.stdio, std.date, std.math;

// local copy of std.math.abs()
// (imported functions are not inlined - see DMD bug #67)
int abs(int x)
{
return x >= 0 ? x : -x;
}

void main()
{
    int sum = 0;
    d_time s = getUTCtime();
    for(int i = 0; i < 100_000_000; i++)
    {
        int val = abs(i);
        sum += val - val;
    }
    d_time e = getUTCtime();
    writefln("std.math.abs(): sum= ",sum,", secs = ",(e -
s)/cast(double)TicksPerSecond);

    d_time tmp = e - s;

    sum = 0;
    s = getUTCtime();
    for(int i = 0; i < 100_000_000; i++)
    {
        int val;
        val = abs(i);
        sum += val - val;
    }
    e = getUTCtime();
    writefln("local abs():    sum= ",sum,", secs = ",(e -
s)/cast(double)TicksPerSecond);

    writefln("ratio = ", tmp / cast(double)(e - s));
}


-- 




More information about the Digitalmars-d-bugs mailing list