Mailing List Archive

[issue14716] Use unicode_writer API for str.format()
New submission from STINNER Victor <victor.stinner@gmail.com>:

I just added a new "unicode_writer" API for the issue #14687 (Optimize str%tuple for the PEP 393) which helps to make "str%tuple" between 25% and 30% faster.

Attached patch replaces PyAccu API with the unicode_writer API for str.format().

Python 3.2:

1000000 loops, best of 3: 0.198 usec per loop
100000 loops, best of 3: 11.3 usec per loop
10000000 loops, best of 3: 0.167 usec per loop
1000000 loops, best of 3: 0.494 usec per loop

Python 3.3:

1000000 loops, best of 3: 0.293 usec per loop
10000 loops, best of 3: 20.2 usec per loop
1000000 loops, best of 3: 0.219 usec per loop
1000000 loops, best of 3: 0.909 usec per loop

Python 3.3 + patch (speed up of the patch):

1000000 loops, best of 3: 0.226 usec per loop (-22%)
100000 loops, best of 3: 14.8 usec per loop (-26%)
1000000 loops, best of 3: 0.219 usec per loop (0%)
1000000 loops, best of 3: 0.658 usec per loop (-27%)

----------
components: Interpreter Core
files: unicode_format_writer.patch
keywords: patch
messages: 159879
nosy: haypo, kristjan.jonsson, loewis, pitrou, python-dev, storchaka
priority: normal
severity: normal
status: open
title: Use unicode_writer API for str.format()
type: performance
versions: Python 3.3
Added file: http://bugs.python.org/file25445/unicode_format_writer.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14716>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue14716] Use unicode_writer API for str.format() [ In reply to ]
STINNER Victor <victor.stinner@gmail.com> added the comment:

Oh, I forgot the benchmark script:
------------
$ cat ~/bench_format.sh
./python -m timeit \
-s 'fmt="{}:"; arg="abc"' \
'fmt.format(arg)'
./python -m timeit \
-s 'N=200; L=3; fmt="{}"*N; args=("a"*L,)*N' \
'fmt.format(*args)'
./python -m timeit \
-s 's="x=%s, y=%u, z=%x"; args=(123, 456, 789)' \
's.format(*args)'
./python -m timeit \
-s 's="The {k1} is {k2} the {k3}."; args={"k1": "x", "k2": "y", "k3": "z"}' \
's.format(**args)'
------------
(based on the one used for #14687, see msg159822)

----------

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14716>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue14716] Use unicode_writer API for str.format() [ In reply to ]
Changes by Eric V. Smith <eric@trueblade.com>:


----------
nosy: +eric.smith

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14716>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue14716] Use unicode_writer API for str.format() [ In reply to ]
Roundup Robot <devnull@psf.upfronthosting.co.za> added the comment:

New changeset 7be716a47e9d by Victor Stinner in branch 'default':
Close #14716: str.format() now uses the new "unicode writer" API instead of the
http://hg.python.org/cpython/rev/7be716a47e9d

New changeset ab500b297900 by Victor Stinner in branch 'default':
Issue #14716: Change integer overflow check in unicode_writer_prepare()
http://hg.python.org/cpython/rev/ab500b297900

----------
resolution: -> fixed
stage: -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14716>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue14716] Use unicode_writer API for str.format() [ In reply to ]
Roundup Robot <devnull@psf.upfronthosting.co.za> added the comment:

New changeset 01581e8b50f2 by Victor Stinner in branch 'default':
Backout ab500b297900: the check for integer overflow is wrong
http://hg.python.org/cpython/rev/01581e8b50f2

----------

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue14716>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com