New submission from Serhiy Storchaka <storch...@gmail.com>: This patch slightly optimize conversion int to string with base 2, 8 or 16 by calculating exactly number of digits and avoiding unnecessary memory allocation. The code is similar to used for decimal conversion.
Without patch: $ ./python -m timeit -s 'x=1' 'bin(x)' 1000000 loops, best of 3: 0.295 usec per loop $ ./python -m timeit -s 'x=1' 'oct(x)' 1000000 loops, best of 3: 0.327 usec per loop $ ./python -m timeit -s 'x=1' 'hex(x)' 1000000 loops, best of 3: 0.298 usec per loop $ ./python -m timeit -s 'x=9**999' 'bin(x)' 100000 loops, best of 3: 11.9 usec per loop $ ./python -m timeit -s 'x=9**999' 'oct(x)' 100000 loops, best of 3: 4.55 usec per loop $ ./python -m timeit -s 'x=9**999' 'hex(x)' 100000 loops, best of 3: 3.99 usec per loop With patch: $ ./python -m timeit -s 'x=1' 'bin(x)' 1000000 loops, best of 3: 0.213 usec per loop $ ./python -m timeit -s 'x=1' 'oct(x)' 1000000 loops, best of 3: 0.228 usec per loop $ ./python -m timeit -s 'x=1' 'hex(x)' 1000000 loops, best of 3: 0.215 usec per loop $ ./python -m timeit -s 'x=9**999' 'bin(x)' 100000 loops, best of 3: 9.76 usec per loop $ ./python -m timeit -s 'x=9**999' 'oct(x)' 100000 loops, best of 3: 3.58 usec per loop $ ./python -m timeit -s 'x=9**999' 'hex(x)' 100000 loops, best of 3: 3.3 usec per loop ---------- components: Library (Lib) files: long_to_binary_base.patch keywords: patch messages: 156085 nosy: storchaka priority: normal severity: normal status: open title: Optimizing bin, oct and hex type: performance versions: Python 3.3 Added file: http://bugs.python.org/file24891/long_to_binary_base.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue14339> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com