import time BIG = 10 ** 6 data = bytearray(b'A'* BIG + b'B' * BIG) third = BIG // 3 data[third:2*third] = b'B' * third data = bytes(data) pattern1 = b"B" * (BIG - 1) pattern2 = b"B" * BIG t0 = time.perf_counter() data.find(pattern1) print(time.perf_counter() - t0) t0 = time.perf_counter() data.find(pattern2) print(time.perf_counter() - t0)