After watching Andre's sentinel thing, I'm playing with strlen on char strings with 4 terminating 0s instead of a single one. Seems to work and is 4x faster compared to the runtime version.

nothrow pure size_t strlen2(const(char)* c) {
 if (c is null)
   return 0;
 size_t l=0;
 while (*c){ c+=4; l+=4;}
 while (*c==0){ c--; l--;}
 return l+1;
}

This is the timing of my test case, which I can post if anyone is interested.
strlen\Release>strlen
2738
681


  • 4x faster strlen with 4 ch... Jay Norwood via Digitalmars-d-announce
    • Re: 4x faster strlen ... David Nadlinger via Digitalmars-d-announce
      • Re: 4x faster str... Jay Norwood via Digitalmars-d-announce
        • Re: 4x faster... chmike via Digitalmars-d-announce
          • Re: 4x fa... chmike via Digitalmars-d-announce
            • Re: ... Ola Fosheim Grøstad via Digitalmars-d-announce
              • ... Jay Norwood via Digitalmars-d-announce
                • ... Ola Fosheim Grøstad via Digitalmars-d-announce
                • ... Jay Norwood via Digitalmars-d-announce
                • ... Ola Fosheim Grøstad via Digitalmars-d-announce
                • ... Jay Norwood via Digitalmars-d-announce

Reply via email to