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