46
46
"""
47
47
48
48
49
- @dataclass
49
+ @dataclass ( frozen = True )
50
50
class Entry :
51
51
point : float
52
52
stderr : float
53
53
54
54
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
60
60
61
61
62
62
def main (root_dir : Path ):
63
- groups = {
63
+ entries = {
64
64
"big_table" : {},
65
65
"teams" : {},
66
66
}
67
- names = {}
67
+ crates = set ()
68
68
units = {
69
69
"big_table" : ("µs" , 1000 ),
70
70
"teams" : ("ns" , 1 ),
@@ -77,16 +77,25 @@ def main(root_dir: Path):
77
77
estimates = load (f )
78
78
79
79
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 )
81
82
point = estimates ["median" ]["point_estimate" ] / units [group ][1 ]
82
83
stderr = estimates ["median" ]["standard_error" ] / units [group ][1 ]
83
84
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
+ ),
90
99
)
91
100
92
101
f = StringIO ()
@@ -100,36 +109,22 @@ def main(root_dir: Path):
100
109
print ("<table>" , file = f )
101
110
print ("<thead>" , file = f )
102
111
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 )
107
116
print ("</thead>" , file = f )
108
117
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 :
112
119
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
+ )
133
128
print ("</tr>" , file = f )
134
129
print ("</tbody>" , file = f )
135
130
print ("<tfoot>" , file = f )
0 commit comments