Practice #5
Lesson 12 of 12 in Coddy's Python Decorators course.
Challenge
EasyWrite a decorator named memory_usage that measures the memory usage of a function.
The decorator should print a message indicating the amount of memory used by the function before and after it is executed, in the following format:
Memory usage: 0 BytesTo get the current "memory usage" (not exactly),
import tracemalloc
tracemalloc.start()
res = # some operations
current, peak = tracemalloc.get_traced_memory()current will hold the value in Bytes.
Return the result of the function in the end!
Try it yourself