checkmem(var, descend=1, order='size', compresslevel=0, maxitems=1000, subtotals=True, plot=False, verbose=False, **kwargs)[source]#

Checks how much memory the variable or variables in question use by dumping them to file.

Note on the different functions:

  • sc.memload() checks current total system memory consumption

  • sc.checkram() checks RAM (virtual memory) used by the current Python process

  • sc.checkmem() checks memory consumption by a given object

  • var (any) – the variable being checked

  • descend (bool) – whether or not to descend one level into the object

  • order (str) – order in which to list items: “size” (default), “alphabetical”, or “none”

  • compresslevel (int) – level of compression to use when saving to file (typically 0)

  • maxitems (int) – the maximum number of separate entries to check the size of

  • subtotals (bool) – whether to include subtotals for different levels of depth

  • plot (bool) – if descending, show the results as a pie chart

  • verbose (bool or int) – detail to print, if >1, print repr of objects along the way

  • **kwargs (dict) – passed to sc.load()


import numpy as np
import sciris as sc

list_obj = ['label', np.random.rand(2483,589)])

nested_dict = dict(
    foo = dict(
        a = np.random.rand(5,10),
        b = np.random.rand(5,20),
        c = np.random.rand(5,50),
    bar = [
    cat = np.random.rand(5,10),

New in version 3.0.0: descend multiple levels; dataframe output; “alphabetical” renamed “order”