Skip to content

Instantly share code, notes, and snippets.

@jabooth
Created July 26, 2014 22:56
Show Gist options
  • Select an option

  • Save jabooth/cf6d0803422068f2d3f2 to your computer and use it in GitHub Desktop.

Select an option

Save jabooth/cf6d0803422068f2d3f2 to your computer and use it in GitHub Desktop.
Speeding Up Menpo Initialization
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:22e1801e60bb108b7fca636d93228e4d199c07700fb298afdd04daecc57e3cfd"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's see, how long does it currently take to import Menpo?"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%time\n",
"import menpo"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"CPU times: user 320 ms, sys: 64.2 ms, total: 384 ms\n",
"Wall time: 401 ms\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Can't get around importing numpy. How long does that take?"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%time\n",
"import numpy"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"CPU times: user 43 ms, sys: 17.3 ms, total: 60.3 ms\n",
"Wall time: 58 ms\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Timing's below are with numpy already imported - we just have to pay that toll."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%time\n",
"import menpo"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"CPU times: user 290 ms, sys: 50.9 ms, total: 340 ms\n",
"Wall time: 357 ms\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"That makes sense - roughly 50ms comes off the time if you pre-import numpy. Let's hunt for other expensive imports..."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%time\n",
"from skimage.transform import pyramid_gaussian\n",
"from skimage.transform.pyramids import _smooth"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"CPU times: user 141 ms, sys: 31.5 ms, total: 173 ms\n",
"Wall time: 173 ms\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%time\n",
"from scipy.stats import multivariate_normal\n",
"from scipy.linalg import norm\n",
"from scipy.ndimage import map_coordinates\n",
"from scipy.ndimage import binary_erosion\n",
"from scipy.linalg.blas import dgemm\n",
"from scipy import optimize\n",
"from scipy.spatial import Delaunay\n",
"from scipy.spatial.distance import cdist"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"CPU times: user 120 ms, sys: 21 ms, total: 141 ms\n",
"Wall time: 139 ms\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%time\n",
"import cyassimp"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"CPU times: user 47.4 ms, sys: 2.07 ms, total: 49.4 ms\n",
"Wall time: 49.4 ms\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%time\n",
"from vrml.vrml97.parser import buildParser as buildVRML97Parser\n",
"import vrml.vrml97.basenodes as basenodes\n",
"from vrml.node import NullNode"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"CPU times: user 14.9 ms, sys: 5.9 ms, total: 20.8 ms\n",
"Wall time: 20 ms\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%time\n",
"import cyrasterize"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"CPU times: user 4.63 ms, sys: 2.5 ms, total: 7.13 ms\n",
"Wall time: 7.14 ms\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%time\n",
"import PIL.Image as PILImage"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"CPU times: user 1.07 ms, sys: 1.27 ms, total: 2.33 ms\n",
"Wall time: 2.32 ms\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%time\n",
"import scipy"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"CPU times: user 1.12 ms, sys: 898 \u00b5s, total: 2.02 ms\n",
"Wall time: 1.92 ms\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Menpo after all above..."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# pre-import all these things...\n",
"import numpy\n",
"import scipy\n",
"import cyassimp\n",
"import cyrasterize\n",
"from vrml.vrml97.parser import buildParser as buildVRML97Parser\n",
"import vrml.vrml97.basenodes as basenodes\n",
"from vrml.node import NullNode\n",
"import PIL.Image as PILImage\n",
"from skimage.transform import pyramid_gaussian\n",
"from skimage.transform.pyramids import _smooth\n",
"from scipy.stats import multivariate_normal\n",
"from scipy.linalg import norm\n",
"from scipy.ndimage import map_coordinates\n",
"from scipy.ndimage import binary_erosion\n",
"from scipy.linalg.blas import dgemm\n",
"from scipy import optimize\n",
"from scipy.spatial import Delaunay\n",
"from scipy.spatial.distance import cdist"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%time\n",
"import menpo"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"CPU times: user 28.9 ms, sys: 11.8 ms, total: 40.7 ms\n",
"Wall time: 60.4 ms\n"
]
}
],
"prompt_number": 2
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment