Skip to content

Commit

Permalink
Merge pull request #268 from AaltoSciComp/rkdarst/jupyter-bash-magic
Browse files Browse the repository at this point in the history
content/jupyter: Use timeit as first cell magic example
  • Loading branch information
bast authored Nov 6, 2023
2 parents fe61dcf + 9b7a48e commit 46de36f
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion content/jupyter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,43 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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):"
"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):"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"54.1 ms ± 993 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
"source": [
"%%timeit\n",
"for x in range(1000000):\n",
" x**2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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):"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
Expand Down

0 comments on commit 46de36f

Please sign in to comment.