Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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