[Python-Dev] New stringbench benchmark results

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Oct 7 06:53:26 CEST 2011


Steven D'Aprano wrote:

> Given that strings are immutable, would it not be an obvious 
> optimization for replace to return the source string unchanged if the 
> old and new substrings are equal,

Only if this situation occurs frequently enough to outweigh
the overhead of comparing the target and replacement strings.

This check could be performed very cheaply when both strings
are interned, so it might be worth doing in that case.

-- 
Greg


More information about the Python-Dev mailing list