How do I display unicode value stored in a string variable using ord()

Terry Reedy tjreedy at udel.edu
Sat Aug 18 16:09:14 EDT 2012


On 8/18/2012 12:38 PM, wxjmfauth at gmail.com wrote:
> Sorry guys, I'm not stupid (I think). I can open IDLE with
> Py 3.2 ou Py 3.3 and compare strings manipulations. Py 3.3 is
> always slower. Period.

You have not tried enough tests ;-).

On my Win7-64 system:
from timeit import timeit

print(timeit(" 'a'*10000 "))
3.3.0b2: .5
3.2.3: .8

print(timeit("c in a", "c  = '…'; a = 'a'*10000"))
3.3: .05 (independent of len(a)!)
3.2: 5.8  100 times slower! Increase len(a) and the ratio can be made as 
high as one wants!

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

Similar with encoding='utf-8' added to call.

Jim, please stop the ranting. It does not help improve Python. utf-32 is 
not a panacea; it has problems of time, space, and system compatibility 
(Windows and others). Victor Stinner, whatever he may have once thought 
and said, put a *lot* of effort into making the new implementation both 
correct and fast.

On your replace example
 >>> imeit.timeit("('ab…' * 1000).replace('…', '……')")
 > 61.919225272152346
 >>> timeit.timeit("('ab…' * 10).replace('…', 'œ…')")
 > 1.2918679017971044

I do not see the point of changing both length and replacement. For me, 
the time is about the same for either replacement. I do see about the 
same slowdown ratio for 3.3 versus 3.2 I also see it for pure search 
without replacement.

print(timeit("c in a", "c  = '…'; a = 'a'*1000+c"))
# .6 in 3.2.3, 1.2 in 3.3.0

This does not make sense to me and I will ask about it.

-- 
Terry Jan Reedy





More information about the Python-list mailing list