Created
April 9, 2021 14:34
-
-
Save agoose77/9ec7c54e0658891875896c7db4957439 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
import argparse | |
import gc | |
import numpy as np | |
import os | |
import pathlib | |
import psutil | |
kB = 1024 | |
MB = 1024 * kB | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser() | |
parser.add_argument("file", type=pathlib.Path) | |
parser.add_argument("-c","--chunk-size", type=int, default=10*MB) | |
args = parser.parse_args() | |
proc = psutil.Process() | |
data = np.memmap(args.file, dtype='uint8', mode='r') | |
i = 0 | |
while True: | |
j = i + args.chunk_size | |
chunk = data[i: j] | |
i = j | |
# Do work | |
chunk.sum() | |
gc.collect() | |
print(f"Memory: {proc.memory_full_info().rss} MB") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment