~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/zlay

atproto relay in zig · mirror of https://tangled.org/zat.dev/zlay

0
0
31 lines · 2.1 KB Raw History
import csv,hashlib,io,json,subprocess,tempfile,platform,sys
from pathlib import Path
import re
root=Path(__file__).resolve().parents[2]
out=Path(sys.argv[2]).resolve()
out.mkdir(parents=True,exist_ok=False)
binary=Path(sys.argv[1]).resolve()
meta={'platform':platform.platform(),'binary_sha256':hashlib.sha256(binary.read_bytes()).hexdigest(),'source_revision':subprocess.check_output(['git','rev-parse','HEAD'],cwd=root,text=True).strip(),'source_files':{str(p.relative_to(root)):hashlib.sha256(p.read_bytes()).hexdigest() for p in [root/'build.zig',root/'build.zig.zon',*sorted((root/'src').rglob('*.zig'))]}}
dependency = re.search(r'\.zkv = \.\{ \.path = "([^"]+)"', (root / 'build.zig.zon').read_text())
assert dependency is not None
core = (root / dependency.group(1)).resolve()
meta['core_revision'] = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=core, text=True).strip()
meta['core_files'] = {
    str(p.relative_to(core)): hashlib.sha256(p.read_bytes()).hexdigest()
    for p in sorted((core / 'src').rglob('*.zig'))
}
(out / 'core.diff').write_bytes(subprocess.check_output(['git', 'diff', 'HEAD'], cwd=core))
(out/'source.diff').write_bytes(subprocess.check_output(['git','diff'],cwd=root))
with tempfile.TemporaryDirectory(prefix='zlay-read-cost-') as td:
 result=subprocess.run([str(binary),td],check=True,text=True,capture_output=True,timeout=90)
(out/'results.csv').write_text(result.stdout)
(out/'run.log').write_text(result.stderr)
rows=list(csv.DictReader(io.StringIO(result.stdout)))
for repo, files in ((root, meta['source_files']), (core, meta['core_files'])):
    assert all(hashlib.sha256((repo / path).read_bytes()).hexdigest() == value for path, value in files.items()), 'source changed during probe'
assert len(rows)==32 and all(r['verified_pairs']=='8448' for r in rows)
(out/'environment.json').write_text(json.dumps(meta,indent=2)+'\n')
import statistics
for case in range(4):
 subset=[r for r in rows if int(r['case'])==case]
 print(case,subset[0]['mode'],{f:round(statistics.median(int(r[f]) for r in subset)/1000,2) for f in ['refresh_ns','page_after_refresh_ns','unchanged_refresh_ns','task_ns']},flush=True)