{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5d91e955-ef4d-47a0-a254-9e3f64f46deb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-01-19T13:29:53.935775Z",
     "iopub.status.busy": "2026-01-19T13:29:53.935488Z",
     "iopub.status.idle": "2026-01-19T13:29:54.959307Z",
     "shell.execute_reply": "2026-01-19T13:29:54.959026Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 69096 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "[encoded data, 69564 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from brokenaxes import brokenaxes\n",
    "import pandas as pd\n",
    "\n",
    "for dark in [True, False]:\n",
    "    # Define colors - using original benchmarks colors for faded, more saturated for solid\n",
    "    if dark:\n",
    "        plt.style.use(\"dark_background\")\n",
    "        color_native_faded = '#8dd3c7'\n",
    "        color_browser_faded = '#feffb3'\n",
    "        color_native = '#00d4aa'  # cyan\n",
    "        color_browser = '#ffff00'  # yellow\n",
    "    else:\n",
    "        plt.style.use(\"default\")\n",
    "        color_native_faded = '#b3c6e0'   # light blue\n",
    "        color_browser_faded = '#f7b6b6'  # light red\n",
    "        color_native = '#1f77b4'         # blue\n",
    "        color_browser = '#d62728'        # red\n",
    "\n",
    "    # Old benchmarks (alpha.13) from old_commit/\n",
    "    df1_old = pd.read_csv(\"native_download_alpha13.csv\", header=0)\n",
    "    df2_old = pd.read_csv(\"browser_download_alpha13.csv\", header=0)\n",
    "\n",
    "    # New benchmarks (alpha.14) from harness/\n",
    "    df1_new = pd.read_csv(\"native_download_alpha14.csv\", header=0)\n",
    "    df2_new = pd.read_csv(\"browser_download_alpha14.csv\", header=0)\n",
    "\n",
    "    # Filter for download_sweep group\n",
    "    df1_old = df1_old[df1_old['group'] == 'download_sweep']\n",
    "    df2_old = df2_old[df2_old['group'] == 'download_sweep']\n",
    "    df1_new = df1_new[df1_new['group'] == 'download_sweep']\n",
    "    df2_new = df2_new[df2_new['group'] == 'download_sweep']\n",
    "\n",
    "    # Calculate mean and standard deviation for error bars\n",
    "    agg1_old = df1_old.groupby(\"download_size\")[\"time_total\"].agg(['mean', 'std']).reset_index()\n",
    "    agg2_old = df2_old.groupby(\"download_size\")[\"time_total\"].agg(['mean', 'std']).reset_index()\n",
    "    agg1_new = df1_new.groupby(\"download_size\")[\"time_total\"].agg(['mean', 'std']).reset_index()\n",
    "    agg2_new = df2_new.groupby(\"download_size\")[\"time_total\"].agg(['mean', 'std']).reset_index()\n",
    "\n",
    "    # Fill NaN std values with 0 (for single data points)\n",
    "    agg1_old['std'] = agg1_old['std'].fillna(0)\n",
    "    agg2_old['std'] = agg2_old['std'].fillna(0)\n",
    "    agg1_new['std'] = agg1_new['std'].fillna(0)\n",
    "    agg2_new['std'] = agg2_new['std'].fillna(0)\n",
    "\n",
    "    # Plot with error bars - alpha.14 first (for legend order), then alpha.13\n",
    "    plt.errorbar(agg1_new[\"download_size\"]/1024.0, agg1_new[\"mean\"]/1000.0, \n",
    "                 yerr=agg1_new[\"std\"]/1000.0, label=\"native alpha.14\", color=color_native, \n",
    "                 capsize=3, capthick=1, elinewidth=1)\n",
    "    plt.errorbar(agg2_new[\"download_size\"]/1024.0, agg2_new[\"mean\"]/1000.0, \n",
    "                 yerr=agg2_new[\"std\"]/1000.0, label=\"browser alpha.14\", color=color_browser, \n",
    "                 capsize=3, capthick=1, elinewidth=1)\n",
    "    plt.errorbar(agg1_old[\"download_size\"]/1024.0, agg1_old[\"mean\"]/1000.0, \n",
    "                 yerr=agg1_old[\"std\"]/1000.0, label=\"native alpha.13\", linestyle=':', \n",
    "                 color=color_native_faded, alpha=0.5, capsize=3, capthick=1, elinewidth=1)\n",
    "    plt.errorbar(agg2_old[\"download_size\"]/1024.0, agg2_old[\"mean\"]/1000.0, \n",
    "                 yerr=agg2_old[\"std\"]/1000.0, label=\"browser alpha.13\", linestyle=':', \n",
    "                 color=color_browser_faded, alpha=0.5, capsize=3, capthick=1, elinewidth=1)\n",
    "\n",
    "    plt.xlabel(\"Response size (KB)\")\n",
    "    plt.ylabel(\"Runtime (sec)\")\n",
    "    plt.title(\"Response size effect on protocol runtime\")\n",
    "\n",
    "    plt.xticks(list(range(0, 55, 5)))\n",
    "    plt.yticks(list(range(0, 35, 5)))\n",
    "\n",
    "    plt.xlim(0, 50)\n",
    "    plt.ylim(0, 35)\n",
    "\n",
    "    # Create legend and grey out alpha.13 entries\n",
    "    legend = plt.legend(loc=\"upper left\")\n",
    "    for i, text in enumerate(legend.get_texts()):\n",
    "        if \"alpha.13\" in text.get_text():\n",
    "            text.set_color('#888888')  # grey color for alpha.13\n",
    "\n",
    "    plt.grid(True, linestyle=\"--\", color='gray', alpha=0.3)\n",
    "\n",
    "    svg_name = \"download_dark.svg\" if dark else \"download_light.svg\"\n",
    "    plt.savefig(svg_name, bbox_inches=\"tight\")\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f61c9fb-7176-4f79-8537-772256a0443d",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "76dddf3c-94cd-4b24-ad4c-172a9bb133f4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16aaacfc-5c3f-43fd-8149-7e19b40577b9",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7f7a83f8-b14e-4b12-b181-1db5eb853aef",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "29b36958-84dd-4eb8-a082-44e70d99cc9d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
