WojciechMula / toys

Storage for my snippets, toy programs, etc.
BSD 2-Clause "Simplified" License
316 stars 38 forks source link

remove zero2 from cmp loop #13

Closed KWillets closed 4 years ago

KWillets commented 4 years ago

String comparison only requires two comparisons, one to zero and one between strings. The case where the other string has a zero is covered either by inequality or the first string.

Byte-level comparison is simplified to comparison at the first diff or null.

The benchmark is about 50% faster.

WojciechMula commented 4 years ago

Wow, that's a cool observation. Thanks a lot!