Your benchmarking results are consistent with the reality of how Python handles these operations. While f-strings are known for being efficient in many cases, they do not inherently optimize string concatenation operations that involve slicing or combining strings.
Why String Addition Can Be Faster in This Case String Addition (+):
String concatenation using + is straightforward: Python internally allocates enough memory for the resulting string and directly appends the components. When the strings involved are simple slices (a[:2], b, a[2:]), this operation is quite efficient. For your specific case, the + operation avoids extra formatting steps, directly performing the concatenation. F-Strings (f'{a[:2]}{b}{a[2:]}'):
F-strings are powerful and flexible, but they involve formatting logic under the hood. Python first evaluates the expressions inside the {} brackets, then formats them into a single string. This added layer of processing (especially evaluating multiple slices like a[:2] and a[2:]) introduces overhead that makes f-strings slower than + concatenation in this particular scenario.