On 09/13/2015 01:16 PM, Daniel N wrote:
On Sunday, 13 September 2015 at 14:06:46 UTC, Martin Nowak wrote:
  struct Foo
  {
      size_t id;
      int opCmp(Foo rhs)
      {
          if (id < rhs.id) return -1;
          if (id == rhs.id) return 0;
          else return 1;
      }
      bool opBinary(string s:"<")(Foo rhs)
      {
          return id < rhs.id;
      }
  }

  Sorting a million Foos w/ random ids is 37.5% slower with opCmp.


Could you try this?

int opCmp(Foo rhs)
{
   return (id > rhs.id) - (id < rhs.id);
}

Apparently that does well with gcc: http://stackoverflow.com/questions/10996418/efficient-integer-compare-function -- Andrei

Reply via email to