From 783550be8108dec25fa48c5530543a1ea1c30d9f Mon Sep 17 00:00:00 2001 From: John Wiggins Date: Mon, 1 Mar 2021 18:11:53 +0100 Subject: [PATCH] Add links to benchmark image outputs --- enable/gcbench/publish.py | 56 +++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/enable/gcbench/publish.py b/enable/gcbench/publish.py index c6a0c56dc..29262b68e 100644 --- a/enable/gcbench/publish.py +++ b/enable/gcbench/publish.py @@ -28,6 +28,12 @@ th {{ text-align: left; }} + td.valid {{ + background: lightgreen; + }} + td.invalid {{ + background: lightpink; + }}

Kiva Backend Benchmark Results

@@ -60,32 +66,54 @@ def publish(results, outdir): # Scale timing values relative to a "baseline" backend implementation for name in functions.keys(): - functions[name] = _format_stats(functions[name], "kiva.agg") + functions[name] = _format_stats(functions[name], name, "kiva.agg") - # Build some table data - headers = ["Draw Function"] + backends - headers = "\n".join(f"{head}" for head in headers) - rows = [ - [f"{name}"] + [f"{stats[bend]}" for bend in backends] - for name, stats in functions.items() - ] - rows = ["".join(row) for row in rows] - rows = "\n".join(f"{row}" for row in rows) - table = _TABLE_TEMPLATE.format(headers=headers, rows=rows) + table = _build_table(backends, functions) path = os.path.join(outdir, "index.html") with open(path, "w") as fp: fp.write(_DOC_TEMPLATE.format(content=table)) -def _format_stats(function, baseline): +def _build_table(backends, functions): + """ Build some table data + """ + # All the row data + rows = [] + for name, stats in functions.items(): + # Start the row off with the name of the function + row = [f"{name}"] + for bend in backends: + # Each backend stat includes a "valid" flag + stat, valid = stats[bend] + # Which gets used to add a CSS class for styling + klass = "valid" if valid else "invalid" + row.append(f'{stat}') + # Concat all the 's into a single string + rows.append("".join(row)) + # Concat all the 's into a multiline string. + rows = "\n".join(f"{row}" for row in rows) + + # Headers + headers = ["Draw Function"] + backends + headers = "\n".join(f"{head}" for head in headers) + + # Smash it all together in the template + return _TABLE_TEMPLATE.format(headers=headers, rows=rows) + + +def _format_stats(function, func_name, baseline): + """ Convert stats for individual benchmark runs into data for a table cell. + """ basevalue = function[baseline] formatted = {} for name, value in function.items(): if value is math.nan: - formatted[name] = "X" + formatted[name] = ("n/a", False) else: relvalue = basevalue / value - formatted[name] = f"{relvalue:0.2f}" + # Link to the image created by the benchmark + link = f'' + formatted[name] = (f"{link}{relvalue:0.2f}", True) return formatted