Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to benchmark memory?
#1
Hello!
I have 3 solutions to the problem. I would like to choose the best one and present it (so make it sexy and verifiable). I use memory_profiler to see amount of memory that is in use now, but it shows me all the mem consumption line-by-line.

What I would like to have looks like that:
from SomeMemModule import CurrentBytesInUse
start_mem = CurrentBytesInUse()
# alloc mem and run algo
print ('Algo uses %d bytes of mem' % (CurrentBytesInUse() - start_mem) )
# dealloc mem
Is there any easy way available? Thank you in advance!
Reply
#2
Hi,

I'm new to Python, but found the following in my recent research. I'm not sure if it is what you are looking for.
#Reference: https://stackoverflow.com/questions/938733/total-memory-used-by-python-process
#Reference: https://pypi.python.org/pypi/psutil

import os
import psutil

process = psutil.Process(os.getpid())
imemoryusage = process.memory_info().rss
print("Python memory usage is {:,} bytes.".format(imemoryusage))
Lewis
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020