Skip to content

Commit 9b7a48e

Browse files
committed
content/jupyter: Use timeit as first cell magic example
- Related: #64 (makes it slightly bettter but not fully fixing) - Introduce %%timeit as first magic since %%bash doesn't work on all OSs. - Not yet removing %%bash, I'd like to add another magic as an extra example to not make it just about %%timeit - I think that %%prun is most likely option for another demo but it should have a longer example that gives a meaningful profile.
1 parent fe61dcf commit 9b7a48e

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

content/jupyter.ipynb

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,43 @@
201201
"cell_type": "markdown",
202202
"metadata": {},
203203
"source": [
204-
"In addition to raw cells, there are **magics**, which exist outside of Python. They are a property of the runtime itself (in Python's case, they come from **IPython**. For example, the following cell magic [%%bash](https://ipython.readthedocs.io/en/stable/interactive/magics.html#cellmagic-bash) turns the cell into a shell script (may not work on all operating systems):"
204+
"In addition to raw cells, there are **magics**, which exist outside of Python. They are a property of the runtime itself (in Python's case, they come from **IPython**. For example, the following cell magic [%%timeit](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-timeit) will use the {py:mod}`timeit` module to time a cell by running it multiple times):"
205205
]
206206
},
207207
{
208208
"cell_type": "code",
209209
"execution_count": 4,
210+
"metadata": {
211+
"tags": []
212+
},
213+
"outputs": [
214+
{
215+
"name": "stdout",
216+
"output_type": "stream",
217+
"text": [
218+
"54.1 ms ± 993 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
219+
]
220+
}
221+
],
222+
"source": [
223+
"%%timeit\n",
224+
"for x in range(1000000):\n",
225+
" x**2"
226+
]
227+
},
228+
{
229+
"cell_type": "markdown",
210230
"metadata": {},
231+
"source": [
232+
"Another example is [%%bash](https://ipython.readthedocs.io/en/stable/interactive/magics.html#cellmagic-bash) which will turn the cell into a shell script (This will only work on operating systems with the Bash shell installed - MacOS and Linux at least):"
233+
]
234+
},
235+
{
236+
"cell_type": "code",
237+
"execution_count": 5,
238+
"metadata": {
239+
"tags": []
240+
},
211241
"outputs": [
212242
{
213243
"name": "stdout",

0 commit comments

Comments
 (0)