1

I try to compare different algorithms' performance in one script. Without using profiler, are there any methods we could use to estimate the memory usage at the end of each algorithm implementation?

def main():
    test_case = open('text.txt', 'r')
    for line in test_case.readlines(): #input different datasets
       #do something in Alg1
       #evaluate memory usage in Alg1
       #do something in Alg2
       #evaluate memory usage in Alg2

1 Answer 1

1

Assuming you are using Linux or Mac OS X;

You can use the standard library module resource to get the total memory consumption as bytes for the calling process:

>>> import resource
>>> resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
19968000
Sign up to request clarification or add additional context in comments.

1 Comment

Do you mean I put your second line at #evaluate memory usage in Alg each time?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.