4 ms·
This code seems inconclusive -- my first three runs showed that lists are the same, slower, AND faster! (updated for Python 3.5.2 on Windows) C:\Temp>p
by psyklic 10y ago
This code seems inconclusive -- my first three runs showed that lists are the same, slower, AND faster! (updated for Python 3.5.2 on Windows)
C:\Temp>python listtuple.py
The tuple's size is 80048 and the list's size is 80064
Iterating through a 10,000 element list took 0.0005006790161132812 seconds.
Iterating through a 10,000 element tuple took 0.0005006790161132812 seconds.
C:\Temp>python listtuple.py
The tuple's size is 80048 and the list's size is 80064
Iterating through a 10,000 element list took 0.0020074844360351562 seconds.
Iterating through a 10,000 element tuple took 0.001031637191772461 seconds.
C:\Temp>python listtuple.py
The tuple's size is 80048 and the list's size is 80064
Iterating through a 10,000 element list took 0.0 seconds.
Iterating through a 10,000 element tuple took 0.001001596450805664 seconds.
- ratsbane 10y agoInteresting! The previous example I posted was Python 2.7.12 on Ubuntu 16.04.01. Here is OSX 10.11.5 w/Python 2.7.10 (also inconclusive with respect to speed, but OSX was half the memory): mb:~ doug$ ./listtuple The tuple's size is 40028 and the list's size is 40036 Iterating through a 10,000 element list took 0.00113916397095 seconds. Iterating through a 10,000 element tuple took 0.00111603736877 seconds. mb:~ doug$ ./listtuple The tuple's size is 40028 and the list's size is 40036 Iterating through a 10,000 element list took 0.00126791000366 seconds. Iterating through a 10,000 element tuple took 0.00133585929871 seconds. mb:~ doug$ ./listtuple The tuple's size is 40028 and the list's size is 40036 Iterating through a 10,000 element list took 0.00114607810974 seconds. Iterating through a 10,000 element tuple took 0.00117492675781 seconds.