[Bug 67] New: Imported functions are not inlined.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Mar 22 06:55:19 PST 2006


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

           Summary: Imported functions 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 identical functions, one inlined,
    the other not.
   There is about a 7x difference on my system.
*/

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

// local copy of std.math.abs()
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++)
    {
        sum += std.math.abs(i);
        sum -= std.math.abs(-i);
    }
    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++)
    {
        sum += .abs(i);
        sum -= .abs(-i);
    }
    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