import random
length = 1000000
# Eager creation: lists
included = [random.random() for _ in range(length)]
missing = [random.random() for _ in range(length)]
def create_set(items):
return set(items)
def create_dict(items):
return {i: 1 for i in items}
@profile
def bench():
# Creation
s = create_set(included)
d = create_dict(included)
# Insertion
for i in missing:
s.add(i)
for i in missing:
d[i] = 1
# Deletion
for i in missing:
s.remove(i)
for i in missing:
d.pop(i)
# Membership test (included)
for i in included:
assert i in s
for i in included:
assert i in d
# Membership test (missing)
for i in missing:
assert i not in s
for i in missing:
assert i not in d
bench()