Skip to content

Commit 3bea21a

Browse files
committed
Sort table sorting
1 parent 32eaad5 commit 3bea21a

File tree

1 file changed

+37
-42
lines changed

1 file changed

+37
-42
lines changed

generate-table.py

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,25 @@
4646
"""
4747

4848

49-
@dataclass
49+
@dataclass(frozen=True)
5050
class Entry:
5151
point: float
5252
stderr: float
5353

5454

55-
def null(i):
56-
if i >= 10:
57-
return f"{i:.1f}"
58-
else:
59-
return f" {i:.1f}"
55+
@dataclass(frozen=True)
56+
class Crate:
57+
function_id: str
58+
name: str
59+
version: str
6060

6161

6262
def main(root_dir: Path):
63-
groups = {
63+
entries = {
6464
"big_table": {},
6565
"teams": {},
6666
}
67-
names = {}
67+
crates = set()
6868
units = {
6969
"big_table": ("µs", 1000),
7070
"teams": ("ns", 1),
@@ -77,16 +77,25 @@ def main(root_dir: Path):
7777
estimates = load(f)
7878

7979
group = benchmark["group_id"].split()[0]
80-
name, version = benchmark["function_id"].split(maxsplit=1)
80+
function_id = benchmark["function_id"]
81+
name, version = function_id.split(maxsplit=1)
8182
point = estimates["median"]["point_estimate"] / units[group][1]
8283
stderr = estimates["median"]["standard_error"] / units[group][1]
8384

84-
names.setdefault(name, [version, 0])[1] += point
85-
groups[group][name] = Entry(point, stderr)
86-
87-
names = sorted(
88-
((name, version, point) for name, [version, point] in names.items()),
89-
key=lambda entry: entry[2],
85+
crates.add(Crate(function_id, name, version))
86+
entries[group][function_id] = Entry(point, stderr)
87+
88+
spread = {}
89+
for key, values in entries.items():
90+
start = min(entry.point - entry.stderr for entry in values.values())
91+
size = max(entry.point + entry.stderr for entry in values.values()) - start
92+
spread[key] = (start, size)
93+
crates = sorted(
94+
crates,
95+
key=lambda crate: sum(
96+
(entries[key][crate.function_id].point - spread[key][0]) / spread[key][1]
97+
for key in entries
98+
),
9099
)
91100

92101
f = StringIO()
@@ -100,36 +109,22 @@ def main(root_dir: Path):
100109
print("<table>", file=f)
101110
print("<thead>", file=f)
102111
print("<tr>", file=f)
103-
print("<th>crate</th>", file=f)
104-
print("<th>version</th>", file=f)
105-
print('<th>big table <abbr title="microseconds = 10^-6 s">(µs)</abbr></th>', file=f)
106-
print('<th>teams <abbr title="nanoseconds = 10^-9 s">(ns)<abbr></th>', file=f)
112+
print("<th>Crate</th>", file=f)
113+
print("<th>Version</th>", file=f)
114+
print('<th>Big Table <abbr title="microseconds = 10^-6 s">(µs)</abbr></th>', file=f)
115+
print('<th>Teams <abbr title="nanoseconds = 10^-9 s">(ns)<abbr></th>', file=f)
107116
print("</thead>", file=f)
108117
print("<tbody>", file=f)
109-
for name, version, _ in names:
110-
big_table = groups["big_table"][name]
111-
teams = groups["teams"][name]
118+
for crate in crates:
112119
print("<tr>", file=f)
113-
print("<td>", name, "</td>", file=f)
114-
print("<td>", version, "</td>", file=f)
115-
print(
116-
"<td>",
117-
f"{big_table.point:,.1f}",
118-
" <small>(± ",
119-
null(big_table.stderr),
120-
")</small></td>",
121-
sep="",
122-
file=f,
123-
)
124-
print(
125-
"<td>",
126-
f"{teams.point:,.1f}",
127-
" <small>(± ",
128-
null(teams.stderr),
129-
")</small></td>",
130-
sep="",
131-
file=f,
132-
)
120+
print("<td>", crate.name, "</td>", file=f)
121+
print("<td>", crate.version, "</td>", file=f)
122+
for values in entries.values():
123+
value = values[crate.function_id]
124+
print(
125+
f"<td>{value.point:,.1f} <small>(± {value.stderr:,.1f})</small></td>",
126+
file=f,
127+
)
133128
print("</tr>", file=f)
134129
print("</tbody>", file=f)
135130
print("<tfoot>", file=f)

0 commit comments

Comments
 (0)