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, mark.dickinson, pitrou, serhiy.storchaka, vstinner
Date 2012-09-24.23:25:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1348529121.01.0.658434105163.issue16001@psf.upfronthosting.co.za>
In-reply-to
Content
Here is a micro benchmark:
---
# run it using:
# benchmark.py script bench_int_str.py [--file=output]
# https://bitbucket.org/haypo/misc/src/tip/python/benchmark.py

def run_benchmark(bench):
    bench.timeit('S(123)', setup='S=str')
    bench.timeit('S(1) == S(2)', setup='S=str')
    bench.timeit('S(12345)', setup='S=str')
    bench.timeit('{S(x): x for x in data}', setup='data=tuple(range(100)); S=str')
    bench.timeit('"x=%s" % x', setup='x=123')
    bench.timeit('"x=%s" % x', setup='x=12345')
---

Output:
-------------------------------------------------------+-------------+---------------
Tests                                                  |   unpatched |        patched
-------------------------------------------------------+-------------+---------------
S=str; S(123)                                          |  158 ns (*) |  112 ns (-29%)
S=str; S(1) == S(2)                                    |  329 ns (*) |  248 ns (-25%)
S=str; S(12345)                                        |  161 ns (*) |         161 ns
data=tuple(range(100)); S=str; {S(x): x for x in data} |   23 us (*) | 16.5 us (-28%)
x=123; "x=%s" % x                                      |  145 ns (*) |   133 ns (-8%)
x=12345; "x=%s" % x                                    |  149 ns (*) |         145 ns
-------------------------------------------------------+-------------+---------------
Total                                                  | 23.9 us (*) | 17.3 us (-27%)
-------------------------------------------------------+-------------+---------------

I expected more important speedup.
History
Date User Action Args
2012-09-24 23:25:21vstinnersetrecipients: + vstinner, loewis, mark.dickinson, pitrou, serhiy.storchaka
2012-09-24 23:25:21vstinnersetmessageid: <1348529121.01.0.658434105163.issue16001@psf.upfronthosting.co.za>
2012-09-24 23:25:20vstinnerlinkissue16001 messages
2012-09-24 23:25:20vstinnercreate