Created
July 29, 2024 17:14
-
-
Save ollien/d71bc5b209a1cd69426d2905e01d534f to your computer and use it in GitHub Desktop.
Tracemalloc Test, Narrowed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[~/Documents/code] nick.krichevsky@M3M-NKrichevsky$ python3 tracemalloc_test.py | |
Total: 64, Peak: 30040 | |
Total: 64, Peak: 363040 | |
Total: 64, Peak: 30040 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tracemalloc | |
def allocate(n): | |
list(range(n)) | |
def print_snap(snap: tracemalloc.Snapshot): | |
for (i, frame) in enumerate(snap.statistics('traceback')): | |
print(f' Frame {i}: {frame}') | |
tracemalloc.start() | |
allocate(1000) | |
total, peak = tracemalloc.get_traced_memory() | |
tracemalloc.stop() | |
print(f"Total: {total}, Peak: {peak}") | |
tracemalloc.start() | |
allocate(10000) | |
total, peak = tracemalloc.get_traced_memory() | |
tracemalloc.stop() | |
print(f"Total: {total}, Peak: {peak}") | |
tracemalloc.start() | |
allocate(1000) | |
total, peak = tracemalloc.get_traced_memory() | |
tracemalloc.stop() | |
print(f"Total: {total}, Peak: {peak}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment