Created
August 15, 2018 07:34
-
-
Save toddlipcon/cb9c52907bbc416b055ffdaa34aaaa77 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 python | |
import re | |
import sys | |
def parse(path): | |
counts = {} | |
sizes = {} | |
for l in file(path): | |
if ':' not in l: | |
# skip header lines | |
continue | |
try: | |
rank, count, size, clazz = re.split(r'\s+', l.strip()) | |
except: | |
raise Exception("bad line: %s" % l) | |
counts[clazz] = int(count) | |
sizes[clazz] = int(size) | |
return counts, sizes | |
def print_diff(before, after): | |
all_keys = set(before.keys()).union(after.keys()) | |
diffs = [] | |
for clazz in all_keys: | |
diffs.append((clazz, after.get(clazz, 0) - before.get(clazz, 0))) | |
diffs.sort(key=lambda x: x[1]) | |
for clazz, diff in diffs: | |
print "%s: %d -> %d (%s%d)" % ( | |
clazz, before.get(clazz, 0), after.get(clazz, 0), | |
diff > 0 and '+' or '', | |
diff) | |
before_counts, before_sizes = parse(sys.argv[1]) | |
after_counts, after_sizes = parse(sys.argv[2]) | |
print "count diffs:" | |
print "-" * 70 | |
print_diff(before_counts, after_counts) | |
print "size diffs:" | |
print "-" * 70 | |
print_diff(before_sizes, after_sizes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment