3 ms·
Strange comparison. I'm not sure who would want to use the trivial double-linked list implementation in Python in real code. Especially if you can do: def
by viraptor 17y ago
Strange comparison. I'm not sure who would want to use the trivial double-linked list implementation in Python in real code. Especially if you can do:
def method2:
chain = [Person(x) for x in xrange(i)]
chain = chain[:2] + chain[4:]
which is 4x faster:
timeit method1: 23.7072529793
timeit method2: 5.78906202316
- d0mine 17y ago`method2` looks buggy. On the question "who whould want to use", here's an example: OrderedSet could be implemented using double-linked list http://code.activestate.com/recipes/576696-orderedset-with-weakrefs/ http://code.activestate.com/recipes/576696-orderedset-with-w... Here's "real code" from stdlib (OrderedDict implementation) http://svn.python.org/view/python/trunk/Lib/collections.py?view=markup http://svn.python.org/view/python/trunk/Lib/collections.py?v...
- viraptor 17y ago> `method2` looks buggy. Claim looks unfounded. (unless you can tell what looks buggy) I'm not sure why they used a D-L list, but thanks for the link - I'll try to reimplement it with standard lists in a bit and run some bigger benchmark on it. Maybe collections need some tweaking? (I'm not saying list is always faster, only that it is for this specific example)