Jupyter notebook to create many_cells in the same dir


In [ ]:
import (
    "fmt"
    "os"
)

(func() {
    f, err := os.Create("many_cells.ipynb")
    if err != nil {
        fmt.Printf("Failed to open: %v\n", err)
    }
    defer f.Close()
    f.WriteString(`{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# many cells\n",
    "This notebook demonstrates lgo can handle thousands of cells though lgo builds and loads shared objects file on every executions."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import (\n",
    "    \"fmt\"\n",
    "    \"strings\"\n",
    "    \"time\"\n",
    ")\n",
    "\n",
    "interval := 64\n",
    "start := time.Now()\n",
    "var sum int64\n",
    "var msgs []string"
   ]
  },
`)
    for i := 1; i <= 1024; i++ {
        f.WriteString(fmt.Sprintf(`{
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "{\n",
    "    n := %d\n",
    "    sum += int64(n)\n",
    "    if n %% interval == 0 {\n",
    "        end := time.Now()\n",
    "        msgs = append(\n",
    "            msgs,\n",
    "            fmt.Sprintf(\"cycle: [%%d, %%d], took %%v on average\", n - interval + 1, n, end.Sub(start)/time.Duration(interval)))\n",
    "        start = end\n",
    "    }\n",
    "}"
   ]
  },
`, i))   
    }
    f.WriteString(`{
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "524800\n"
     ]
    }
   ],
   "source": [
    "sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cycle: [1, 64], took 684.526294ms on average\n",
      "cycle: [65, 128], took 672.778457ms on average\n",
      "cycle: [129, 192], took 681.855261ms on average\n",
      "cycle: [193, 256], took 674.783885ms on average\n",
      "cycle: [257, 320], took 686.477005ms on average\n",
      "cycle: [321, 384], took 683.289412ms on average\n",
      "cycle: [385, 448], took 687.293805ms on average\n",
      "cycle: [449, 512], took 693.450195ms on average\n",
      "cycle: [513, 576], took 672.261078ms on average\n",
      "cycle: [577, 640], took 682.784516ms on average\n",
      "cycle: [641, 704], took 691.448044ms on average\n",
      "cycle: [705, 768], took 671.875065ms on average\n",
      "cycle: [769, 832], took 673.786842ms on average\n",
      "cycle: [833, 896], took 681.162642ms on average\n",
      "cycle: [897, 960], took 672.475553ms on average\n",
      "cycle: [961, 1024], took 680.732248ms on average\n",
      "765\n",
      "<nil>\n"
     ]
    }
   ],
   "source": [
    "fmt.Println(strings.Join(msgs, \"\\n\"))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Go (lgo)",
   "language": "go",
   "name": "lgo"
  },
  "language_info": {
   "file_extension": "",
   "mimetype": "",
   "name": "go",
   "version": ""
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
`)
})()