Align a variable on the stack.
    TheFlyingFiddle via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Thu Nov  5 15:37:43 PST 2015
    
    
  
On Thursday, 5 November 2015 at 21:24:03 UTC, TheFlyingFiddle 
wrote:
> On Thursday, 5 November 2015 at 21:22:18 UTC, TheFlyingFiddle 
> wrote:
>> On Thursday, 5 November 2015 at 11:14:50 UTC, Marc Schütz 
>> wrote:
>> ~10x slowdown...
>
> I forgot to mention this but I am using DMD 2.069.0-rc2 for x86 
> windows.
I reduced it further:
struct A { float x, y, z ,w; }
struct B
{
    float x=float.nan;
    float y=float.nan;
    float z=float.nan;
    float w=float.nan;
}
void initVal(T)(ref T t, ref float k) { pragma(inline, false); }
void benchA()
{
    foreach(float f; 0 .. 1000_000)
    {
       A val = A.init;
       initVal(val, f);
    }
}
void benchB()
{
    foreach(float f; 0 .. 1000_000)
    {
       B val = B.init;
       initVal(val, f);
    }
}
int main(string[] argv)
{
    import std.datetime;
    import std.stdio;
    auto res = benchmark!(benchA, benchB)(1);
    writeln("Default:  ", res[0]);
    writeln("Explicit: ", res[1]);
    readln;
    return 0;
}
also i am using dmd -release -boundcheck=off -inline
The pragma(inline, false) is there to prevent it from removing 
the assignment in the loop.
    
    
More information about the Digitalmars-d-learn
mailing list