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 serhiy.storchaka
Recipients loewis, mark.dickinson, pitrou, serhiy.storchaka, vstinner
Date 2012-05-09.08:03:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1336550749.2591.22.camel@raxxla>
In-reply-to <1336521522.38.0.748341957924.issue14744@psf.upfronthosting.co.za>
Content
> Here is a new patch using _PyUnicodeWriter directly in longobject.c.

It may be worth to do it in a separate issue?

decimal digits) is 17% faster with my patch version 2 compared to tip,
and 38% faster compared to Python 3.3 before my optimizations on str%
tuples or str.format(). Creating a temporary PyUnicode is not cheap, at
least for short strings.

Here is my benchmark script (attached) and the results:

Python 3.3 (vanilla):

1.65	str(12345)
2.6	'{}'.format(12345)
2.69	'A{}'.format(12345)
3.16	'\x80{}'.format(12345)
3.23	'\u0100{}'.format(12345)
3.32	'\U00010000{}'.format(12345)
4.6	'{:-10}'.format(12345)
4.89	'A{:-10}'.format(12345)
5.53	'\x80{:-10}'.format(12345)
5.71	'\u0100{:-10}'.format(12345)
5.63	'\U00010000{:-10}'.format(12345)
4.6	'{:,}'.format(12345)
4.71	'A{:,}'.format(12345)
5.28	'\x80{:,}'.format(12345)
5.65	'\u0100{:,}'.format(12345)
5.59	'\U00010000{:,}'.format(12345)

Python 3.3 + format_writer.patch:

1.72	str(12345)
2.74	'{}'.format(12345)
2.99	'A{}'.format(12345)
3.4	'\x80{}'.format(12345)
3.52	'\u0100{}'.format(12345)
3.51	'\U00010000{}'.format(12345)
4.24	'{:-10}'.format(12345)
4.6	'A{:-10}'.format(12345)
5.16	'\x80{:-10}'.format(12345)
6.87	'\u0100{:-10}'.format(12345)
6.83	'\U00010000{:-10}'.format(12345)
4.12	'{:,}'.format(12345)
4.6	'A{:,}'.format(12345)
5.09	'\x80{:,}'.format(12345)
6.63	'\u0100{:,}'.format(12345)
6.42	'\U00010000{:,}'.format(12345)

Python 3.3 + format_writer-2.patch: 

1.91	str(12345)
2.44	'{}'.format(12345)
2.61	'A{}'.format(12345)
3.08	'\x80{}'.format(12345)
3.31	'\u0100{}'.format(12345)
3.13	'\U00010000{}'.format(12345)
4.57	'{:-10}'.format(12345)
4.96	'A{:-10}'.format(12345)
5.52	'\x80{:-10}'.format(12345)
7.01	'\u0100{:-10}'.format(12345)
7.34	'\U00010000{:-10}'.format(12345)
4.42	'{:,}'.format(12345)
4.76	'A{:,}'.format(12345)
5.16	'\x80{:,}'.format(12345)
7.2	'\u0100{:,}'.format(12345)
6.74	'\U00010000{:,}'.format(12345)

As you can see, there is a regress, and sometimes it is not less than
improvement.
Files
File name Uploaded
issue14744-bench-1.py serhiy.storchaka, 2012-05-09.08:03:21
History
Date User Action Args
2012-05-09 08:03:22serhiy.storchakasetrecipients: + serhiy.storchaka, loewis, mark.dickinson, pitrou, vstinner
2012-05-09 08:03:21serhiy.storchakalinkissue14744 messages
2012-05-09 08:03:21serhiy.storchakacreate