This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author alexandre.vassalotti
Recipients alexandre.vassalotti
Date 2009-08-11.21:34:35
SpamBayes Score 5.0774396e-08
Marked as misclassified No
Message-id <1250026477.34.0.625583102893.issue6688@psf.upfronthosting.co.za>
In-reply-to
Content
Optimize PyBytes_FromObject by adding special-cases for list and tuple
objects and by using _PyObject_LengthHint() instead of an arbitrary
value for the size of the initial buffer.

[Without the patch]
./python -m timeit -s "x = list(range(256))" "bytes(x)"
100000 loops, best of 3: 7.19 usec per loop

./python -m timeit -s "x = tuple(range(256))" "bytes(x)"
100000 loops, best of 3: 7.14 usec per loop

./python -m timeit -s "x = list(range(256))*100" "bytes(x)"
1000 loops, best of 3: 591 usec per loop

./python -m timeit -s "x = range(256)" "bytes(x)"
100000 loops, best of 3: 8.45 usec per loop


[With the patch]

./python -m timeit -s "x = list(range(256))" "bytes(x)"
100000 loops, best of 3: 4.43 usec per loop

./python -m timeit -s "x = tuple(range(256))" "bytes(x)"
100000 loops, best of 3: 4.53 usec per loop

./python -m timeit -s "x = list(range(256))*100" "bytes(x)"
1000 loops, best of 3: 335 usec per loop

./python -m timeit -s "x = range(256)" "bytes(x)"
100000 loops, best of 3: 7.56 usec per loop
History
Date User Action Args
2009-08-11 21:34:37alexandre.vassalottisetrecipients: + alexandre.vassalotti
2009-08-11 21:34:37alexandre.vassalottisetmessageid: <1250026477.34.0.625583102893.issue6688@psf.upfronthosting.co.za>
2009-08-11 21:34:36alexandre.vassalottilinkissue6688 messages
2009-08-11 21:34:36alexandre.vassalotticreate