Message159508
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 |
|
Date |
User |
Action |
Args |
2012-04-28 00:47:59 | vstinner | set | recipients:
+ vstinner, loewis, pitrou |
2012-04-28 00:47:58 | vstinner | set | messageid: <1335574078.74.0.597228078235.issue14687@psf.upfronthosting.co.za> |
2012-04-28 00:47:57 | vstinner | link | issue14687 messages |
2012-04-28 00:47:57 | vstinner | create | |
|