[Issue 255] Odd performance difference w/ complex doubles.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 16 19:39:13 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=255

Andrei Alexandrescu <andrei at erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |WORKSFORME

--- Comment #4 from Andrei Alexandrescu <andrei at erdani.com> ---
Adapted the code to the current D compiler, here's the code:

=================================================
import std.stdio, std.string;
void main(char[][] args)
{
  char  bit_num = 0, byte_acc = 0;
  const int iter = 50;
  const double lim = 2.0 * 2.0;
version(foo)
{
  cdouble Z, C;
}
 import core.stdc.stdlib;

  int n = atoi(args[1].toStringz);

  writefln("P4\n%d %d",n,n);

  for(int y=0; y<n; y++)
    for(int x=0; x<n; x++)
    {
version(foo)
{}
else
{
       cdouble Z,C;
}
       Z = 0 + 0i;
       C = 2*cast(double)x/n - 1.5 + 2i*cast(double)y/n - 1i;

       for(int i = 0; i < iter && norm(Z) <= lim; i++)
         Z = Z*Z + C;

       byte_acc = cast(char) ((byte_acc << 1) | ((norm(Z) > lim) ? 0x00:0x01));

       bit_num++;
       if(bit_num == 8)
       {
           //putc(byte_acc,core.stdc.stdio.stdout);
           bit_num = byte_acc = 0;
       }
       else if(x == n-1)
       {
           byte_acc  <<= (8-n%8);
           //putc(byte_acc,core.stdc.stdio.stdout);
           bit_num = byte_acc = 0;
       }
    }
}

double norm(cdouble C)
{
    return C.re*C.re + C.im*C.im;
}
=================================================

Then built two versions like this (file is test.d):

=================================================
$ dmd -O -inline -release -version=foo -oftestfoo test
$ dmd -O -inline -release test
=================================================

Then I measured like this:

=================================================
$ time ./testfoo 10000
P4
10000 10000
./testfoo 10000  17.70s user 0.00s system 99% cpu 17.704 total
$ time ./test 10000
P4
10000 10000
./test 10000  17.71s user 0.00s system 99% cpu 17.714 total
=================================================

I'll close this as "works for me", please reopen if I missed something. Thanks!

--


More information about the Digitalmars-d-bugs mailing list