[New-bugs-announce] [issue22687] horrible performance of textwrap.wrap() with a long word

Piotr Engelking report at bugs.python.org
Tue Oct 21 18:45:26 CEST 2014


New submission from Piotr Engelking:

Wrapping a paragraph containing a long word takes a lot of time:

$ time python3 -c 'import textwrap; textwrap.wrap("a" * 2 ** 16)'

real	3m14.923s
user	3m14.792s
sys	0m0.016s
$

A straightforward replacement is 5000 times faster:

$ time python3 -c '("".join(x) for x in zip(*[iter("a" * 2 ** 16)] * 70))'

real	0m0.053s
user	0m0.032s
sys	0m0.016s
$

Tested on Debian with python3.4 3.4.2-1 and python2.7 2.7.8-10.

----------
messages: 229768
nosy: inkerman
priority: normal
severity: normal
status: open
title: horrible performance of textwrap.wrap() with a long word
type: performance
versions: Python 2.7, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22687>
_______________________________________


More information about the New-bugs-announce mailing list