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 vstinner
Recipients loewis, pitrou, vstinner
Date 2012-04-28.00:47:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1335574078.74.0.597228078235.issue14687@psf.upfronthosting.co.za>
In-reply-to
Content
PyUnicode_Format() creates short temporary substrings. Attached patch tries to avoid substrings. For example, it avoids write of 1 character and repetition of 1 character like a space. PyUnicode_Format() now works in two steps:

 - computes the maximum character and the length of the output string
 - write characters into the output string

I'm not sure that my patch is correct, nor that the change does really speed-up Python.


Benchmark:

./python -m timeit \
  -s 's="x=%s, y=%u, z=%x"; args=(123, 456, 789)' \
  's%args'
./python -m timeit \
  -s 's="The %(k1)s is %(k2)s the %(k3)s."; args={"k1":"x","k2":"y","k3":"z",}' \
  's%args'

Python 3.2:

1000000 loops, best of 3: 0.482 usec per loop
1000000 loops, best of 3: 0.295 usec per loop

Python 3.3:

1000000 loops, best of 3: 0.653 usec per loop
1000000 loops, best of 3: 0.666 usec per loop

Python 3.3 + patch:

1000000 loops, best of 3: 0.596 usec per loop
1000000 loops, best of 3: 0.566 usec per loop
History
Date User Action Args
2012-04-28 00:47:59vstinnersetrecipients: + vstinner, loewis, pitrou
2012-04-28 00:47:58vstinnersetmessageid: <1335574078.74.0.597228078235.issue14687@psf.upfronthosting.co.za>
2012-04-28 00:47:57vstinnerlinkissue14687 messages
2012-04-28 00:47:57vstinnercreate