tracemalloc.Snapshot.compare_to()
tracemalloc.Snapshot.compare_to() is a Python method in the Tracemalloc Module category. Compares two snapshots to find memory differences. The syntax is Snapshot.compare_to(old_snapshot, key_type, cumulative=False). Returns: List of StatisticDiff objects. A typical example: diff = snap2.compare_to(snap1, "lineno")
for d in diff[:5]:
print(f"{d.size_diff:+d} bytes - {d.traceback}"). A close sibling is tracemalloc.start(), which starts tracing memory allocations. A close sibling is tracemalloc.stop(), which stops tracing memory allocations. A close sibling is tracemalloc.get_traced_memory(), which returns (current_size, peak_size) of traced memory in bytes. A close sibling is tracemalloc.take_snapshot(), which takes a snapshot of memory allocations. More about this category: Memory tracing — start, stop, get_traced_memory, Snapshot, take_snapshot. Related Tracemalloc Module entries: tracemalloc.start(), tracemalloc.stop(), tracemalloc.get_traced_memory(), tracemalloc.take_snapshot(), tracemalloc.Snapshot.statistics(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try tracemalloc.Snapshot.compare_to() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.