Skip to content

Instantly share code, notes, and snippets.

@ayorgo
Created June 9, 2020 19:37
Show Gist options
  • Save ayorgo/01617deaf1fc3d0171b59a674cf60ce4 to your computer and use it in GitHub Desktop.
Save ayorgo/01617deaf1fc3d0171b59a674cf60ce4 to your computer and use it in GitHub Desktop.
from typing import List
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from memory_profiler import memory_usage
from multiprocessing import Pool, cpu_count
import gc
def mem_inline(function, *arg) -> float:
return memory_usage(proc=(function, arg), max_usage=True)#[0]
def mem_it(functions: List[str], args):
gc.collect()
results = []
for function in functions:
for arg in args:
results.append(mem_inline(function, arg))
gc.collect()
data = np.reshape(results, (len(functions), len(args)))
result = pd.DataFrame(index=[f.__self__.__class__.__name__ for f in functions], columns=args, data=data)
ax = result.T.plot()
ax.set_xlabel('input size')
ax.set_ylabel('time (MiB)');
functions = [function1,
function2,
function3]
args = [10, 50, 100, 500, 1_000, 5_000, 10_000]
mem_it(functions, args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment