[Python-Dev] 3.3 str timings

Terry Reedy tjreedy at udel.edu
Sat Aug 18 23:17:14 CEST 2012


The issue came up in python-list about string operations being slower in 
3.3. (The categorical claim is false as some things are actually 
faster.) Some things I understand, this one I do not.

Win7-64, 3.3.0b2 versus 3.2.3
print(timeit("c in a", "c  = '…'; a = 'a'*1000+c")) # ord(c) = 8230
# .6 in 3.2, 1.2 in 3.3

Why is searching for a two-byte char in a two-bytes per char string so 
much faster in 3.2? Is this worth a tracker issue (I searched and could 
not find one) or is there a known and un-fixable cause?

print(timeit("a.encode()", "a = 'a'*1000"))
# 1.5 in 3.2, .26 in 3.3

print(timeit("a.encode(encoding='utf-8')", "a = 'a'*1000"))
# 1.7 in 3.2, .51 in 3.3

This is one of the 3.3 improvements. But since the results are equal:
('a'*1000).encode() == ('a'*1000).encode(encoding='utf-8')
and 3.3 should know that for an all-ascii string, I do not see why 
adding the parameter should double the the time. Another issue or known 
and un-fixable?

-- 
Terry Jan Reedy




More information about the Python-Dev mailing list