Sergey added the comment:

Attached fasttuple.py is a Proof-of-Concept implementation of tuple, that 
reuses same data storage when possible. Its possible usage looks similar to 
built-in tuples:
  from fasttuple import ft
  a = ft([1,2])
  b = a + ft([3,4])
  c = b + ft([5,6])
  d = b + ft([7,8])
  d += ft([9])
  d = ft([0]) + d + ft([0])
  print(a, b, c, d)

An interesting side-effect of this implementation is a faster __add__ operator:

Python 2.7.5:
  Adding 100000 of fasttuples
  took 0.23242688179 seconds
  Adding 100000 of built-in tuples
  took 25.2749021053 seconds

Python 3.3.2:
  Adding 100000 of fasttuples
  took 0.2883174419403076 seconds
  Adding 100000 of built-in tuples
  took 25.487935066223145 seconds

(see test() function in fasttuple.py)

This is just a proof of concept, it can be improved in different ways. Similar 
optimization can be applied to lists.

----------
Added file: http://bugs.python.org/file30917/fasttuple.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18305>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to