{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "67c44619",
   "metadata": {},
   "source": [
    "# Core ML Performance Benchmarks 2026\n",
    "\n",
    "This notebook reproduces the benchmark summaries published on 3NSOFTS.\n",
    "\n",
    "Dataset: /public/data/core-ml-benchmarks-2026.csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8f7664a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "df = pd.read_csv('core-ml-benchmarks-2026.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2eb7a25",
   "metadata": {},
   "outputs": [],
   "source": [
    "summary = (\n",
    "    df[(df['quantization'] == 'Float16') & (df['batch_size'] == 1)]\n",
    "    .groupby('device_model')['inference_ms_per_item']\n",
    "    .mean()\n",
    "    .sort_values()\n",
    ")\n",
    "summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6190b368",
   "metadata": {},
   "outputs": [],
   "source": [
    "ax = summary.plot(kind='bar', color='#0f766e', figsize=(9,4))\n",
    "ax.set_title('Average Inference Time by Device (Float16, Batch=1)')\n",
    "ax.set_ylabel('Inference ms per item')\n",
    "ax.set_xlabel('Device')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "da5b80e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "size_reduction = df[df['quantization'] == 'INT8']['model_size_reduction_pct'].mean()\n",
    "speedup = (\n",
    "    df[(df['device_model'] == 'iPhone 12') & (df['quantization'] == 'Float16') & (df['batch_size'] == 1)]['inference_ms_per_item'].mean()\n",
    "    /\n",
    "    df[(df['device_model'] == 'iPhone 16') & (df['quantization'] == 'Float16') & (df['batch_size'] == 1)]['inference_ms_per_item'].mean()\n",
    ")\n",
    "throughput_gain = (\n",
    "    df[(df['quantization'] == 'Float16') & (df['batch_size'] == 8)]['throughput_items_per_sec'].mean()\n",
    "    /\n",
    "    df[(df['quantization'] == 'Float16') & (df['batch_size'] == 1)]['throughput_items_per_sec'].mean()\n",
    ")\n",
    "print(f'iPhone 16 vs iPhone 12 speedup: {speedup:.2f}x')\n",
    "print(f'INT8 average size reduction: {size_reduction:.1f}%')\n",
    "print(f'Batch 8 vs batch 1 throughput gain: {throughput_gain:.2f}x')"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
