Skip to content

Instantly share code, notes, and snippets.

@nmoinvaz
Last active February 8, 2026 07:04
Show Gist options
  • Select an option

  • Save nmoinvaz/fed3b112e2eace506ba7567d24ac05e8 to your computer and use it in GitHub Desktop.

Select an option

Save nmoinvaz/fed3b112e2eace506ba7567d24ac05e8 to your computer and use it in GitHub Desktop.
Deflatebench comparison
import re, sys
def parse_results(path):
results = {}
with open(path) as f:
for line in f:
m = re.match(r'\s+(\d+|avg\d?)\s', line)
if not m:
continue
level = m.group(1)
# Match timing values (4 decimal places) to skip percentages (3 decimal places)
times = re.findall(r'\d+\.\d{4}', line)
if level.startswith('avg'):
# avg lines have single values: comp_time [decomp_time]
results[level] = {
'comp': float(times[0]) if len(times) >= 1 else None,
'decomp': float(times[1]) if len(times) >= 2 else None,
}
else:
# Per-level lines have min/avg/max/stddev groups
results[level] = {
'comp': float(times[1]) if len(times) >= 4 else None,
'decomp': float(times[5]) if len(times) >= 8 else None,
}
return results
def pct_diff(base, head):
if not base or not head:
return None
return ((head - base) / base) * 100
def fmt_diff(diff):
if diff is None:
return 'N/A'
sign = '+' if diff > 0 else ''
return f'{sign}{diff:.1f}%'
base = parse_results('base-results.txt')
head = parse_results('head-results.txt')
lines = []
has_decomp = any(v.get('decomp') is not None for v in base.values())
if has_decomp:
lines.append('| Level | Compress Base | Compress Head | Compress Δ | Decompress Base | Decompress Head | Decompress Δ |')
lines.append('|-------|-------------|-------------|-----------|----------------|----------------|-------------|')
else:
lines.append('| Level | Compress Base | Compress Head | Compress Δ |')
lines.append('|-------|-------------|-------------|-----------|')
for level in sorted(base.keys(), key=lambda x: (x.startswith('avg'), x)):
if level not in head:
continue
b, h = base[level], head[level]
comp_diff = pct_diff(b['comp'], h['comp'])
bold = '**' if level.startswith('avg') else ''
label = f'Overall ({level})' if level.startswith('avg') else level
if has_decomp:
decomp_diff = pct_diff(b.get('decomp'), h.get('decomp'))
lines.append(f'| {bold}{label}{bold} | {bold}{b[\"comp\"]:.4f}{bold} | {bold}{h[\"comp\"]:.4f}{bold} | {bold}{fmt_diff(comp_diff)}{bold} | {bold}{b[\"decomp\"]:.4f}{bold} | {bold}{h[\"decomp\"]:.4f}{bold} | {bold}{fmt_diff(decomp_diff)}{bold} |')
else:
lines.append(f'| {bold}{label}{bold} | {bold}{b[\"comp\"]:.4f}{bold} | {bold}{h[\"comp\"]:.4f}{bold} | {bold}{fmt_diff(comp_diff)}{bold} |')
with open('comparison.md', 'w') as f:
f.write('\n'.join(lines) + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment