New submission from Alexandre Vassalotti <alexan...@peadrop.com>: 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 ---------- components: Interpreter Core files: optimize_bytes_from_object.diff keywords: patch messages: 91486 nosy: alexandre.vassalotti priority: normal severity: normal stage: patch review status: open title: Optimize PyBytes_FromObject. type: performance Added file: http://bugs.python.org/file14694/optimize_bytes_from_object.diff _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6688> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com