Skip to content

Instantly share code, notes, and snippets.

@jmdelaney8
Created February 16, 2023 20:02
Show Gist options
  • Save jmdelaney8/1d7cca8dc6ccc7bba0894eb358729591 to your computer and use it in GitHub Desktop.
Save jmdelaney8/1d7cca8dc6ccc7bba0894eb358729591 to your computer and use it in GitHub Desktop.
test if bistruct.c.compile has a memory leak
import time
import tracemalloc
import bitstruct
STAT_PERIOD = 5 # seconds
little_fmt = 'u24'
names=['requested_pgn']
start = time.perf_counter()
prev_stat_time = time.perf_counter()
prev_snapshot = tracemalloc.take_snapshot()
tracemalloc.start()
while True:
if time.perf_counter() - prev_stat_time > STAT_PERIOD:
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.compare_to(prev_snapshot, 'lineno')
print(f"\nrun time: {round(time.perf_counter() -start)} seconds")
print(f"[ Top 10 differences:]")
for stat in top_stats[:10]:
print(stat)
prev_snapshot = snapshot
prev_stat_time = time.perf_counter()
bitstruct.c.compile(little_fmt, names)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment