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);
}

Reply via email to