{
  "cells" : [
    {
      "cell_type" : "markdown",
      "id" : "58B78AC4-2EB7-49F5-88AA-6AA6E4DF8375",
      "metadata" : {

      },
      "source" : [
        "# Kernel Check\n",
        "\n",
        "Run these cells to verify which Python runtime you're connected to, either **Local (Pyodide\/WASM)** or a **Remote Jupyter Kernel**.\n",
        "\n",
        "Each cell is self-contained, so you can run them individually or all at once."
      ]
    },
    {
      "cell_type" : "code",
      "execution_count" : null,
      "id" : "A0E9E316-AC99-4C73-A78E-4EDDA196FF38",
      "metadata" : {

      },
      "outputs" : [

      ],
      "source" : [
        "import sys\n",
        "import platform\n",
        "\n",
        "print(f\"Platform:        {sys.platform}\")\n",
        "print(f\"OS:              {platform.system()} {platform.release()}\")\n",
        "print(f\"Implementation:  {platform.python_implementation()}\")\n",
        "print(f\"Python version:  {platform.python_version()}\")\n",
        "print(f\"Executable:      {sys.executable or '(none, WASM)'}\")\n",
        "print()\n",
        "\n",
        "if sys.platform == \"emscripten\":\n",
        "    print(\">>> You are running on LOCAL Pyodide (WebAssembly)\")\n",
        "else:\n",
        "    print(f\">>> You are running on a REMOTE Jupyter kernel ({platform.system()})\")"
      ]
    },
    {
      "cell_type" : "markdown",
      "id" : "195D6CD0-DAC4-489D-A655-CE7638084022",
      "metadata" : {

      },
      "source" : [
        "## CPU & Memory"
      ]
    },
    {
      "cell_type" : "code",
      "execution_count" : null,
      "id" : "F4569207-7D81-4EE1-86ED-B166DB8E5A1B",
      "metadata" : {

      },
      "outputs" : [

      ],
      "source" : [
        "import sys\n",
        "import os\n",
        "\n",
        "cpu_count = os.cpu_count()\n",
        "print(f\"CPU cores:  {cpu_count}\")\n",
        "\n",
        "try:\n",
        "    import resource\n",
        "    mem = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss\n",
        "    if sys.platform == \"darwin\":\n",
        "        print(f\"Peak memory: {mem \/ 1024 \/ 1024:.1f} MB\")\n",
        "    else:\n",
        "        print(f\"Peak memory: {mem \/ 1024:.1f} MB\")\n",
        "except Exception:\n",
        "    print(\"Peak memory: (not available on this platform)\")"
      ]
    },
    {
      "cell_type" : "markdown",
      "id" : "BB5CB56C-ABBC-4A0F-B805-9D9B656DBFB9",
      "metadata" : {

      },
      "source" : [
        "## Network Access (Remote Only)\n",
        "\n",
        "Remote kernels have real network access. Pyodide cannot make outbound connections."
      ]
    },
    {
      "cell_type" : "code",
      "execution_count" : null,
      "id" : "0F10F505-5B4E-4E1E-8AD0-4EA55132A1B3",
      "metadata" : {

      },
      "outputs" : [

      ],
      "source" : [
        "try:\n",
        "    import urllib.request\n",
        "    resp = urllib.request.urlopen(\"https:\/\/httpbin.org\/ip\", timeout=5)\n",
        "    data = resp.read().decode()\n",
        "    print(f\"Network access: YES\")\n",
        "    print(f\"Response: {data.strip()}\")\n",
        "except Exception as e:\n",
        "    print(f\"Network access: NO ({type(e).__name__})\")"
      ]
    },
    {
      "cell_type" : "markdown",
      "id" : "4697D7A7-71E9-4B8F-81C9-4487F406E54B",
      "metadata" : {

      },
      "source" : [
        "## Quick Benchmark"
      ]
    },
    {
      "cell_type" : "code",
      "execution_count" : null,
      "id" : "BA73790D-D85C-45E5-B81A-2F8A9C004136",
      "metadata" : {

      },
      "outputs" : [

      ],
      "source" : [
        "import sys\n",
        "import time\n",
        "\n",
        "n = 1_000_000\n",
        "start = time.perf_counter()\n",
        "total = sum(i * i for i in range(n))\n",
        "elapsed = time.perf_counter() - start\n",
        "\n",
        "print(f\"Sum of squares (n={n:,}): {elapsed:.3f}s\")\n",
        "print(f\"Result: {total:,}\")\n",
        "print()\n",
        "\n",
        "if sys.platform == \"emscripten\":\n",
        "    print(\"Tip: Remote kernels are typically 5-10x faster for CPU-bound work.\")\n",
        "else:\n",
        "    print(\"Running on native Python: full CPU speed.\")"
      ]
    }
  ],
  "metadata" : {
    "kernelspec" : {
      "display_name" : "Python 3 (Pyodide)",
      "language" : "python",
      "name" : "python3"
    },
    "language_info" : {
      "name" : "python",
      "version" : "3.14.2"
    }
  },
  "nbformat" : 5,
  "nbformat_minor" : 10
}