preveen-stack / nodejs

0 stars 0 forks source link

using memory_profiler with pythonn #22

Open preveen-stack opened 1 month ago

preveen-stack commented 1 month ago
# Example script to profile memory usage using memory_profiler
from memory_profiler import profile

@profile
def fibonacci(n):
    if n <= 1:
        return n
    else:
        return fibonacci(n-1) + fibonacci(n-2)

def main():
    result = fibonacci(30)

if __name__ == "__main__":
    main()
preveen-stack commented 1 month ago
ilename: /Users/preveen/prevlabs/python/ex-memory-profiler.py

Line #    Mem usage    Increment  Occurrences   Line Contents
=============================================================
     4     46.9 MiB     46.9 MiB           5   @profile
     5                                         def fibonacci(n):
     6     46.9 MiB      0.0 MiB           5       if n <= 1:
     7     46.9 MiB      0.0 MiB           3           return n
     8                                             else:
     9     46.9 MiB      0.0 MiB           2           return fibonacci(n-1) + fibonacci(n-2)