Created
June 23, 2023 17:09
-
-
Save mdvsh/7d91387fdc28e8b5cc14794f500d98c6 to your computer and use it in GitHub Desktop.
mem regex search for large exp log files to find mean of steps to success
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 re, mmap | |
pattern = rb'pick_rsteps\s*:\s*(\d+)\s+place_rsteps\s*:\s*(\d+)' | |
expfnam = ["svfu", "svu", "mr"] | |
nf = 10 | |
for exp in expfnam: | |
means = [] | |
for i in range(nf): | |
with open(f"dat/{exp}{i}.txt", "r") as file: | |
with mmap.mmap(file.fileno(), 0, access=mmap.ACCESS_READ) as mmap_file: | |
match = re.search(pattern, mmap_file) | |
if match: | |
p1, p2 = int(match.group(1)), int(match.group(2)) | |
means.append((p1, p2)) | |
mean_tuple = tuple(map(lambda x: sum(x) / len(means), zip(*means))) | |
print(f"mean {exp}: ", mean_tuple) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment