detkit.Memory#

class detkit.Memory(unit=1)#

Trace memory allocation.

Parameters:
unitint or str {'B', 'KB', 'MB', 'GB', 'TB'}, default=``1``

Unit of memory either as a string, such as 'KB', representing 1024 bytes, or directly specify the number of bytes as an integer.

Examples

>>> from detkit import Memory, memdet
>>> import numpy

>>> # Create a random matrix
>>> A = numpy.random.randn(10000, 10000)

>>> # Initialize with MB unit
>>> mem = Memory(unit='MB')

>>> # Set the starting point of memory inquiry
>>> mem.set()

>>> # Perform a memory-intensive operation
>>> ld = memdet(A)

>>> # Inquiry current allocated memory in MB unit
>>> print(mem.now())
82.3

>>> # Inquiry the peak allocated memory in MB unit
>>> print(mem.peak())
82.3

>>> # Reset the memory counter and inquiry again
>>> mem.set()
>>> print(mem.now())
0.0

Methods

set()

Set or reset tracing allocated memory.

now()

Inquiry current memory allocation.

peak()

Inquiry peak memory allocation since memory is set.

info()

Inquiry memory information.