Created
May 27, 2012 13:11
-
-
Save svartalf/2814163 to your computer and use it in GitHub Desktop.
Test of the list and tuple __getitem__ performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import sys | |
import timeit | |
l = list(range(10)) | |
t = tuple(l) | |
def func(obj): | |
r = list(range(1000)) | |
for i in r: | |
for j in r: | |
c = obj[2] | |
print(sys.version) | |
print(timeit.Timer('func(l)', 'from __main__ import l, func').timeit(number=100)) | |
print(timeit.Timer('func(t)', 'from __main__ import t, func').timeit(number=100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Additional test under a different system