Created
April 3, 2020 20:54
-
-
Save LucasMagnum/f51631dd639d2561a8d87d4d877dabfb to your computer and use it in GitHub Desktop.
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 functools | |
import random | |
import time | |
import sys | |
def timeit(func): | |
@functools.wraps(func) | |
def wrapper(*args, **kwargs): | |
start = time.time() | |
response = func(*args, **kwargs) | |
took = time.time() - start | |
func_name = func.__name__ | |
print(f"{func_name} --> took {took:.2f} ") | |
return response | |
return wrapper | |
@timeit | |
def list_solution(values, collection): | |
for value in values: | |
assert value in collection | |
size = 30_000_000 | |
collection = [x for x in range(size)] | |
collection_size_mb = sys.getsizeof(collection) / 1024 / 1024 | |
print(f"Collection size: {collection_size_mb:.2f}mb") | |
values = [random.randint(0, size) for _ in range(100)] | |
list_solution(values, collection) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment