Created
December 25, 2014 02:49
-
-
Save jeffrey4l/135951ac011c12f8f43d to your computer and use it in GitHub Desktop.
python_in_perf.py
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
import random | |
import timeit | |
S1 = set(range(100)) | |
S2 = range(100) | |
S3 = tuple(range(100)) | |
print type(S1), type(S2), type(S3) | |
def test1(): | |
random.randint(0, 10000) in S1 | |
def test2(): | |
random.randint(0, 10000) in S2 | |
def test3(): | |
random.randint(0, 10000) in S3 | |
print timeit.timeit('test1()', setup="from __main__ import test1") | |
print timeit.timeit('test2()', setup="from __main__ import test2") | |
print timeit.timeit('test3()', setup="from __main__ import test3") | |
# $ python in.py | |
# <type 'set'> <type 'list'> <type 'tuple'> | |
# 1.450715065 | |
# 2.52170777321 | |
# 2.51845502853 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment