Skip to content

Instantly share code, notes, and snippets.

@ramonsaraiva
Created December 30, 2017 23:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramonsaraiva/9116421b9185b217726e400337406c3a to your computer and use it in GitHub Desktop.
Save ramonsaraiva/9116421b9185b217726e400337406c3a to your computer and use it in GitHub Desktop.
from memory_profiler import profile
def chunks_with_list(l):
return [
l[i:i + 100] for i in range(0, len(l), 100)
]
def chunks_with_gen(l):
return (
l[i:i + 100] for i in range(0, len(l), 100)
)
@profile
def chunkify_list_with_list():
l = [0] * 1000000
for _ in chunks_with_list(l):
pass
@profile
def chunkify_list_with_gen():
l = [0] * 1000000
for _ in chunks_with_gen(l):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment