[issue16001] small ints: cache string representation

2012-09-29 Thread STINNER Victor
STINNER Victor added the comment: str(int) is less common than %s % int or %i % int, and str%args has now fast path in Python 3.3 for integers. So I agree that my patch adds useless complexity and I'm closing this idea, thanks. -- resolution: - rejected status: open - closed

[issue16001] small ints: cache string representation

2012-09-28 Thread Jesús Cea Avión
Changes by Jesús Cea Avión j...@jcea.es: -- nosy: +jcea ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16001 ___ ___ Python-bugs-list mailing list

[issue16001] small ints: cache string representation

2012-09-25 Thread Terry J. Reedy
Terry J. Reedy added the comment: Small int caching saves both time and space. On a nearly fresh IDLE session: sys.getrefcount(0) 772 sys.getrefcount(1) 854 sum(sys.getrefcount(i) for i in range(-5, 257)) 4878 While an interesting idea, I do not see the same gain here, and agree with

[issue16001] small ints: cache string representation

2012-09-24 Thread STINNER Victor
STINNER Victor added the comment: My initial idea was to cache str(int) for any integer, but it may waste memory for huge numbers. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16001 ___

[issue16001] small ints: cache string representation

2012-09-24 Thread STINNER Victor
STINNER Victor added the comment: 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) ==

[issue16001] small ints: cache string representation

2012-09-24 Thread STINNER Victor
STINNER Victor added the comment: Oops, I forgot to attach the new patch: small_ints_cache_str-2.patch optimizes also str % args (copy the string when needed if the reference count is not 1). -- Added file: http://bugs.python.org/file27286/small_ints_cache_str-2.patch

[issue16001] small ints: cache string representation

2012-09-24 Thread Martin v . Löwis
Martin v. Löwis added the comment: -1 for this entire effort. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16001 ___ ___ Python-bugs-list

[issue16001] small ints: cache string representation

2012-09-21 Thread STINNER Victor
New submission from STINNER Victor: Integers in range [-5; 256] are singleton. It is possible to cache their string representation (in base 10) to make str(int) faster, but also to reduce memory consumption (and memory fragmentation, Unicode strings don't use free list). Attached patch

[issue16001] small ints: cache string representation

2012-09-21 Thread STINNER Victor
Changes by STINNER Victor victor.stin...@gmail.com: -- nosy: +storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16001 ___ ___

[issue16001] small ints: cache string representation

2012-09-21 Thread STINNER Victor
Changes by STINNER Victor victor.stin...@gmail.com: -- nosy: -ezio.melotti ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16001 ___ ___

[issue16001] small ints: cache string representation

2012-09-21 Thread Antoine Pitrou
Antoine Pitrou added the comment: Honestly, I'm not sure I understand the point of this optimization. Have you identified a workload where this would help? -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org

[issue16001] small ints: cache string representation

2012-09-21 Thread Martin v . Löwis
Martin v. Löwis added the comment: Also, can you report benchmark results? -- nosy: +loewis ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16001 ___