Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save bilalozdemir/faa3ec6afad931d972567cc9b54da94e to your computer and use it in GitHub Desktop.
How to Profile a Python Program - Block 4
from memory_profiler import profile
@profile
def wasteful_sum_function() -> int:
return sum([x**2 for x in range(10**4)])
@profile
def resource_efficient_sum_function() -> int:
return sum((x**2 for x in range(10**4)))
if __name__ == '__main__':
#Profiling functions by executing them seperately
wasteful_sum_function()
resource_efficient_sum_function()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment