#!/usr/bin/env python3 """Verify and measure yyjson parsing with bounded, differently paced consumers.""" import argparse import csv import hashlib import json import os from pathlib import Path import platform import random import shlex import signal import statistics import struct import subprocess import tempfile import time ROOT = Path(__file__).resolve().parent FLAGS = ["-std=c17", "-O2", "-g", "-Wall", "-Wextra", "-Wpedantic", "-Werror"] FLAGS += ["-DYYJSON_DISABLE_WRITER=1", "-DYYJSON_DISABLE_UTILS=1", "-DYYJSON_DISABLE_INCR_READER=1"] SOURCE_NAMES = ["benchmark.c", "run.py", "plan.json", "vendor/yyjson/UPSTREAM.json", "vendor/yyjson/yyjson.c", "vendor/yyjson/yyjson.h", "vendor/yyjson/LICENSE"] def digest(path): with path.open("rb") as stream: return hashlib.file_digest(stream, "sha256").hexdigest() def dump(path, value): path.write_text(json.dumps(value, indent=2, ensure_ascii=False) + "\n") def first_members(pairs): result = {} for key, value in pairs: result.setdefault(key, value) return result def reference(data, keys): values = [[] for _ in keys] for line in data.splitlines(): row = json.loads(line, object_pairs_hook=first_members) if not isinstance(row, dict): raise ValueError("object required") for k, key in enumerate(keys): if not isinstance(row.get(key), str): raise ValueError("string field required") values[k].append(row[key].encode("utf-8")) return values def decode(data, keys, expected, partial=False): at = 0 found = [[] for _ in keys] while at < len(data): if len(data) - at < 16: raise AssertionError("incomplete output header") k, length, sequence = struct.unpack_from("