benchmark_to_chart.py PYTHON 70 lines View on github.com → Search inside
1#!/usr/bin/env python32"""Convert hyperfine JSON output from benchmark.sh into a Google Charts HTML page."""34import json5import re6import sys789def extract_version(command):10    """Extract version from a command like 'scc3.4.0 linux'."""11    m = re.match(r'scc(\d+\.\d+\.\d+)', command)12    return m.group(1) if m else command131415def main():16    if len(sys.argv) < 2:17        print(f"Usage: {sys.argv[0]} benchmark_regression.json [title]")18        sys.exit(1)1920    json_file = sys.argv[1]21    title = sys.argv[2] if len(sys.argv) > 2 else "scc performance linux kernel"2223    with open(json_file) as f:24        data = json.load(f)2526    rows = []27    for result in data["results"]:28        version = extract_version(result["command"])29        mean = result["mean"]30        rows.append(f"          ['{version}', {mean:.3f}]")3132    chart_data = ",\n".join(rows)3334    html = f"""<!DOCTYPE html>35<html>36<head>37  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>38  <script type="text/javascript">39    google.charts.load('current', {{'packages':['corechart']}});40    google.charts.setOnLoadCallback(drawChart);4142    function drawChart() {{43      var data = google.visualization.arrayToDataTable([44        ['Version', 'Runtime (seconds)'],45{chart_data}46      ]);4748      var options = {{49        title: '{title}',50        curveType: 'function',51        legend: {{ position: 'bottom' }}52      }};5354      var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));55      chart.draw(data, options);56    }}57  </script>58</head>59<body>60  <div id="curve_chart" style="width: 900px; height: 500px"></div>61</body>62</html>63"""6465    print(html)666768if __name__ == "__main__":69    main()

Code quality findings 3

Ensure functions have docstrings for documentation
missing-docstring
def main():
Use logging module for better control and configurability
print-statement
print(f"Usage: {sys.argv[0]} benchmark_regression.json [title]")
Use logging module for better control and configurability
print-statement
print(html)

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.