github.com/yunabe/lgo@v0.0.0-20190709125917-42c42d410fdf/examples/many_cells.ipynb (about)

     1  {
     2   "cells": [
     3    {
     4     "cell_type": "markdown",
     5     "metadata": {},
     6     "source": [
     7      "# many cells\n",
     8      "This notebook demonstrates lgo can handle thousands of cells though lgo builds and loads shared objects file on every executions."
     9     ]
    10    },
    11    {
    12     "cell_type": "code",
    13     "execution_count": 1,
    14     "metadata": {},
    15     "outputs": [],
    16     "source": [
    17      "import (\n",
    18      "    \"fmt\"\n",
    19      "    \"strings\"\n",
    20      "    \"time\"\n",
    21      ")\n",
    22      "\n",
    23      "interval := 64\n",
    24      "start := time.Now()\n",
    25      "var sum int64\n",
    26      "var msgs []string"
    27     ]
    28    },
    29    {
    30     "cell_type": "code",
    31     "execution_count": 2,
    32     "metadata": {},
    33     "outputs": [],
    34     "source": [
    35      "{\n",
    36      "    n := 1\n",
    37      "    sum += int64(n)\n",
    38      "    if n % interval == 0 {\n",
    39      "        end := time.Now()\n",
    40      "        msgs = append(\n",
    41      "            msgs,\n",
    42      "            fmt.Sprintf(\"cycle: [%d, %d], took %v on average\", n - interval + 1, n, end.Sub(start)/time.Duration(interval)))\n",
    43      "        start = end\n",
    44      "    }\n",
    45      "}"
    46     ]
    47    },
    48    {
    49     "cell_type": "code",
    50     "execution_count": 3,
    51     "metadata": {},
    52     "outputs": [],
    53     "source": [
    54      "{\n",
    55      "    n := 2\n",
    56      "    sum += int64(n)\n",
    57      "    if n % interval == 0 {\n",
    58      "        end := time.Now()\n",
    59      "        msgs = append(\n",
    60      "            msgs,\n",
    61      "            fmt.Sprintf(\"cycle: [%d, %d], took %v on average\", n - interval + 1, n, end.Sub(start)/time.Duration(interval)))\n",
    62      "        start = end\n",
    63      "    }\n",
    64      "}"
    65     ]
    66    },
    67    {
    68     "cell_type": "markdown",
    69     "metadata": {},
    70     "source": [
    71      "# Note\n",
    72      "Many cells are omitted from this notebook to keep the size small. To get a complete version, run make_many_cells.ipnb in the same dir."
    73     ]
    74    },
    75    {
    76     "cell_type": "code",
    77     "execution_count": 1024,
    78     "metadata": {},
    79     "outputs": [],
    80     "source": [
    81      "{\n",
    82      "    n := 1023\n",
    83      "    sum += int64(n)\n",
    84      "    if n % interval == 0 {\n",
    85      "        end := time.Now()\n",
    86      "        msgs = append(\n",
    87      "            msgs,\n",
    88      "            fmt.Sprintf(\"cycle: [%d, %d], took %v on average\", n - interval + 1, n, end.Sub(start)/time.Duration(interval)))\n",
    89      "        start = end\n",
    90      "    }\n",
    91      "}"
    92     ]
    93    },
    94    {
    95     "cell_type": "code",
    96     "execution_count": 1025,
    97     "metadata": {},
    98     "outputs": [],
    99     "source": [
   100      "{\n",
   101      "    n := 1024\n",
   102      "    sum += int64(n)\n",
   103      "    if n % interval == 0 {\n",
   104      "        end := time.Now()\n",
   105      "        msgs = append(\n",
   106      "            msgs,\n",
   107      "            fmt.Sprintf(\"cycle: [%d, %d], took %v on average\", n - interval + 1, n, end.Sub(start)/time.Duration(interval)))\n",
   108      "        start = end\n",
   109      "    }\n",
   110      "}"
   111     ]
   112    },
   113    {
   114     "cell_type": "code",
   115     "execution_count": 1026,
   116     "metadata": {},
   117     "outputs": [
   118      {
   119       "name": "stdout",
   120       "output_type": "stream",
   121       "text": [
   122        "524800\n"
   123       ]
   124      }
   125     ],
   126     "source": [
   127      "sum"
   128     ]
   129    },
   130    {
   131     "cell_type": "code",
   132     "execution_count": 1027,
   133     "metadata": {},
   134     "outputs": [
   135      {
   136       "name": "stdout",
   137       "output_type": "stream",
   138       "text": [
   139        "cycle: [1, 64], took 684.526294ms on average\n",
   140        "cycle: [65, 128], took 672.778457ms on average\n",
   141        "cycle: [129, 192], took 681.855261ms on average\n",
   142        "cycle: [193, 256], took 674.783885ms on average\n",
   143        "cycle: [257, 320], took 686.477005ms on average\n",
   144        "cycle: [321, 384], took 683.289412ms on average\n",
   145        "cycle: [385, 448], took 687.293805ms on average\n",
   146        "cycle: [449, 512], took 693.450195ms on average\n",
   147        "cycle: [513, 576], took 672.261078ms on average\n",
   148        "cycle: [577, 640], took 682.784516ms on average\n",
   149        "cycle: [641, 704], took 691.448044ms on average\n",
   150        "cycle: [705, 768], took 671.875065ms on average\n",
   151        "cycle: [769, 832], took 673.786842ms on average\n",
   152        "cycle: [833, 896], took 681.162642ms on average\n",
   153        "cycle: [897, 960], took 672.475553ms on average\n",
   154        "cycle: [961, 1024], took 680.732248ms on average\n",
   155        "765\n",
   156        "<nil>\n"
   157       ]
   158      }
   159     ],
   160     "source": [
   161      "fmt.Println(strings.Join(msgs, \"\\n\"))"
   162     ]
   163    }
   164   ],
   165   "metadata": {
   166    "kernelspec": {
   167     "display_name": "Go (lgo)",
   168     "language": "go",
   169     "name": "lgo"
   170    },
   171    "language_info": {
   172     "file_extension": "",
   173     "mimetype": "",
   174     "name": "go",
   175     "version": ""
   176    }
   177   },
   178   "nbformat": 4,
   179   "nbformat_minor": 2
   180  }