Python 3.5, bytes, and %-interpolation (aka PEP 461)

wxjmfauth at gmail.com wxjmfauth at gmail.com
Tue Feb 25 09:07:17 CET 2014


Le mardi 25 février 2014 00:55:36 UTC+1, Steven D'Aprano a écrit :
> 
> 
> 
> However, you don't really want to be adding large numbers of byte strings 
> 
> together, due to efficiency. Better to use % interpolation to insert them 
> 
> all at once. Hence the push to add % to bytes in Python 3.
> 
> 

>>> timeit.timeit("'abc' * 1000 + '\u20ac'")
2.3244550589543564
>>> timeit.timeit("x * 1000 + y", "x = 'abc'.encode('utf-8'); y = '\u20ac'.encode('utf-8')")
0.9365105183684364
>>> timeit.timeit("'\u0153' + 'abc' * 1000 + '\u20ac'")
3.0469319226397715
>>> timeit.timeit("z + x * 1000 + y", "x = 'abc'.encode('utf-8'); y = '\u20ac'.encode('utf-8'); z = '\u0153'.encode('utf-8')")
1.9215464486771339
>>> 

Interpolation will not help.

What is wrong by design will always stay wrong by design.

jmf

>>>



More information about the Python-list mailing list