diff --git a/generate-table.py b/generate-table.py index 7a9ac25..0065b3a 100755 --- a/generate-table.py +++ b/generate-table.py @@ -46,25 +46,25 @@ """ -@dataclass +@dataclass(frozen=True) class Entry: point: float stderr: float -def null(i): - if i >= 10: - return f"{i:.1f}" - else: - return f" {i:.1f}" +@dataclass(frozen=True) +class Crate: + function_id: str + name: str + version: str def main(root_dir: Path): - groups = { + entries = { "big_table": {}, "teams": {}, } - names = {} + crates = set() units = { "big_table": ("µs", 1000), "teams": ("ns", 1), @@ -77,16 +77,25 @@ def main(root_dir: Path): estimates = load(f) group = benchmark["group_id"].split()[0] - name, version = benchmark["function_id"].split(maxsplit=1) + function_id = benchmark["function_id"] + name, version = function_id.split(maxsplit=1) point = estimates["median"]["point_estimate"] / units[group][1] stderr = estimates["median"]["standard_error"] / units[group][1] - names.setdefault(name, [version, 0])[1] += point - groups[group][name] = Entry(point, stderr) - - names = sorted( - ((name, version, point) for name, [version, point] in names.items()), - key=lambda entry: entry[2], + crates.add(Crate(function_id, name, version)) + entries[group][function_id] = Entry(point, stderr) + + spread = {} + for key, values in entries.items(): + start = min(entry.point - entry.stderr for entry in values.values()) + size = max(entry.point + entry.stderr for entry in values.values()) - start + spread[key] = (start, size) + crates = sorted( + crates, + key=lambda crate: sum( + (entries[key][crate.function_id].point - spread[key][0]) # / spread[key][1] + for key in entries + ), ) f = StringIO() @@ -100,36 +109,22 @@ def main(root_dir: Path): print("
crate | ", file=f) - print("version | ", file=f) - print('big table (µs) | ', file=f) - print('teams (ns) | ', file=f) + print("Crate | ", file=f) + print("Version | ", file=f) + print('Big Table (µs) | ', file=f) + print('Teams (ns) | ', file=f) print("
---|---|---|---|---|---|---|---|
", name, " | ", file=f) - print("", version, " | ", file=f) - print( - "", - f"{big_table.point:,.1f}", - " (± ", - null(big_table.stderr), - ") | ", - sep="", - file=f, - ) - print( - "", - f"{teams.point:,.1f}", - " (± ", - null(teams.stderr), - ") | ", - sep="", - file=f, - ) + print("", crate.name, " | ", file=f) + print("", crate.version, " | ", file=f) + for values in entries.values(): + value = values[crate.function_id] + print( + f"{value.point:,.1f} (± {value.stderr:,.1f}) | ", + file=f, + ) print("