Atila Neves: "C IS NOT MAGICALLY FAST, PART 2"

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 19 12:09:27 PDT 2016


On 07/19/2016 12:00 PM, Ali Çehreli wrote:
 > On 07/19/2016 10:41 AM, deadalnix wrote:

 >> if(i < other.i) return -1;
 >> if(i > other.i) return 1;
 >>
 >> Should be
 >>
 >> (i > other.i) - (i < other.i)
 >>
 >> Surprisingly, LLVM was unable to optimize one into the other in my 
tests.

If you mean the following, it's slower with ldc:

         const r = (i > other.i) - (i < other.i) ;
         if (r) return r;

 > Additionally, the string may be traversed twice in opCmp. The following
 > change makes D example faster:
 >
 >          import std.algorithm : cmp;
 >          return cmp(s, other.s);
 > //        return s < other.s
 > //            ? -1
 > //            : (s > other.s ? 1 : 0);

Faster with dmd but has no difference with ldc.

Ali



More information about the Digitalmars-d mailing list