New GitHub issue #119595 from dgrigonis:<br>
<hr>
<pre>
### Bug description:
I thought I will post this in the same issue as although I would not expect these to be unrelated, they strangely do look very similar.
Checked on both Mac and Linux - both return same pattern.
str.find (unicode & bytes):
```python
wc = '_' * 1_000_000
%timeit wc.find('9') # 22 µs
%timeit wc.find('99') # 822 µs
%timeit wc.find('99averagelylongstring99') # 151 µs
```
re.search
```
wc = '_' * 1_000_000
ts0 = tuple(f'{i}' for i in range(100))
ts1 = tuple(f'averagelylongstring{i}' for i in range(100))
ts2 = tuple(f'{i}averagelylongstring{i}' for i in range(100))
c_ts0 = re.compile(r'({})'.format('|'.join(ts0)))
c_ts1 = re.compile(r'({})'.format('|'.join(ts1)))
c_ts2 = re.compile(r'({})'.format('|'.join(ts2)))
# Mac
%timeit next(c_ts0.finditer(wc), None) # 4.5 ms
%timeit next(c_ts1.finditer(wc), None) # 0.4 ms
%timeit next(c_ts2.finditer(wc), None) # 4.5 ms
```
Is this expected?
I started digging `str` case, and I got as far as:
a) single-char case: len(sub) == 1, so it branches out early to `find_char`
b) both (2 & 3) call `asciilib_find_slice` from `any_find_slice`
### CPython versions tested on:
3.11, 3.13
### Operating systems tested on:
Linux, macOS
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/119595">View on GitHub</a>
<p>Labels: type-bug</p>
<p>Assignee: </p>