The worst case behavior happens when the bad character skip is consistently low (with the lower limit of 1 byte movement) and a large portion of the needle matches the haystack. The bad character skip is only low, on a partial match, when the final character of the needle also occurs elsewhere within the needle, with 1 byte movement happening when the same byte is in both of the last two positions. The canonical degenerate case similar to the above "best" case is a needle of an 'a' byte followed by 31 'z' bytes in a haystack consisting of 255 'z' bytes. This will do 31 successful byte comparisons, a 1 byte comparison that fails and then move forward 1 byte. This process will repeat 223 more times (255 − 32), bringing the total byte comparisons to 7,168 (32 × 224). (A different byte-comparison loop will have a different behavior.) The worst case is significantly higher than for the Boyer–Moore string-search algorithm, although obviously this is hard to achieve in normal use cases. It is also worth noting that this worst case is also the worst case for the naive (but usual) memcmp() algorithm, although the implementation of that tends to be significantly optimized (and is more cache friendly). Tuning the comparison loop The original algorithm had a more sophisticated same() loop. It uses an extra pre-check before proceeding in the positive direction: function same_orig(str1, str2, len) i ← 0 if str1[len - 1] = str2[len - 1] while str1[i] = str2[i] if i = len - 2 return true i ← i + 1 return false A tuned version of the BMH algorithm is the Raita algorithm. It adds an additional precheck for the middle character, in the order of last-first-middle. The algorithm enters the full loop only when the check passes: function same_raita(str1, str2, len) i ← 0 mid ← len / 2 Three prechecks. if len ≥ 3 if str[mid] != str2[mid] return false if len ≥ 1 if str[0] != str2[0] return false if len ≥ 2 if str[len - 1] != str2[len - 1] return false Any old comparison loop. return len < 3 or SAME(&str1[1], &str2[1], len - 2) It is unclear whether this 1992 tuning still holds its performance advantage on modern machines. The rationale by the authors is that actual text usually contains some patterns which can be effectively prefiltered by these