[Python-Dev] PEP 393 decode() oddity

Paul Moore p.f.moore at gmail.com
Sun Mar 25 21:12:11 CEST 2012


On 25 March 2012 19:51, Serhiy Storchaka <storchaka at gmail.com> wrote:
> Anyone can test.
>
> $ ./python -m timeit -s 'enc = "latin1"; import codecs; d =
> codecs.getdecoder(enc); x = ("\u0020" * 100000).encode(enc)' 'd(x)'
> 10000 loops, best of 3: 59.4 usec per loop
> $ ./python -m timeit -s 'enc = "latin1"; import codecs; d =
> codecs.getdecoder(enc); x = ("\u0080" * 100000).encode(enc)' 'd(x)'
> 10000 loops, best of 3: 28.4 usec per loop
>
> The results are fairly stable (±0.1 µsec) from run to run. It looks funny
> thing.

Hmm, yes. I see the same results. Odd.

PS D:\Data> py -3.3  -m timeit -s "enc = 'latin1'; import codecs; d =
codecs.getdecoder(enc); x = ('\u0020' * 100000).encode(enc)" "d(x)"
10000 loops, best of 3: 37.3 usec per loop
PS D:\Data> py -3.3  -m timeit -s "enc = 'latin1'; import codecs; d =
codecs.getdecoder(enc); x = ('\u0080' * 100000).encode(enc)" "d(x)"
100000 loops, best of 3: 18 usec per loop
PS D:\Data> py -3.3  -m timeit -s "enc = 'latin1'; import codecs; d =
codecs.getdecoder(enc); x = ('\u0020' * 100000).encode(enc)" "d(x)"
10000 loops, best of 3: 37.6 usec per loop
PS D:\Data> py -3.3  -m timeit -s "enc = 'latin1'; import codecs; d =
codecs.getdecoder(enc); x = ('\u0080' * 100000).encode(enc)" "d(x)"
100000 loops, best of 3: 18.3 usec per loop
PS D:\Data> py -3.3  -m timeit -s "enc = 'latin1'; import codecs; d =
codecs.getdecoder(enc); x = ('\u0020' * 100000).encode(enc)" "d(x)"
10000 loops, best of 3: 37.8 usec per loop
PS D:\Data> py -3.3  -m timeit -s "enc = 'latin1'; import codecs; d =
codecs.getdecoder(enc); x = ('\u0080' * 100000).encode(enc)" "d(x)"
100000 loops, best of 3: 18.3 usec per loop

Paul.


More information about the Python-Dev mailing list