Skip to content

Instantly share code, notes, and snippets.

@infinite-Joy
Created December 17, 2017 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infinite-Joy/1c82f5615ff3f778ca471dd3599cea61 to your computer and use it in GitHub Desktop.
Save infinite-Joy/1c82f5615ff3f778ca471dd3599cea61 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The following cells have dependencies which can be installed using:\n",
"\n",
" pip install line_profiler\n",
" pip install memory_profiler"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%load_ext line_profiler\n",
"%load_ext memory_profiler"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# some small functions for example purposes\n",
"import numpy as np\n",
"\n",
"def func(n, a):\n",
" y = np.arange(n)\n",
" y = np.exp(-y*a)\n",
" return y\n",
"\n",
"def gunc(n, a):\n",
" y = np.exp(-n*a)\n",
" return y\n",
"\n",
"def hunc(n, a):\n",
" y1 = func(n, a)\n",
" y2 = gunc(n, a)\n",
" return y1, y2"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%lprun -f func hunc(50000, 0.5)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"peak memory: 62.31 MiB, increment: 1.10 MiB\n"
]
}
],
"source": [
"%memit hunc(50000, 0.5)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (venv)",
"language": "python",
"name": "venv"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment