Skip to content

Commit

Permalink
Moved a code snippet from profiling_tutorial.rst to the examples dire…
Browse files Browse the repository at this point in the history
…ctory.
  • Loading branch information
gabrieldemarmiesse committed Jun 16, 2018
1 parent 3d291a5 commit d39d579
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
13 changes: 13 additions & 0 deletions docs/examples/tutorial/profiling_tutorial/profile_2.py
@@ -0,0 +1,13 @@
# profile.py

import pstats, cProfile

import pyximport
pyximport.install()

import calc_pi

cProfile.runctx("calc_pi.approx_pi()", globals(), locals(), "Profile.prof")

s = pstats.Stats("Profile.prof")
s.strip_dirs().sort_stats("time").print_stats()
18 changes: 2 additions & 16 deletions docs/src/tutorial/profiling_tutorial.rst
Expand Up @@ -194,23 +194,9 @@ meaningful output from the cProfile module. The rest of the code is mostly
unchanged, I only typed some variables which will likely speed things up a bit.

We also need to modify our profiling script to import the Cython module directly.
Here is the complete version adding the import of the :ref:`Pyximport<pyximport>` module::
Here is the complete version adding the import of the :ref:`Pyximport<pyximport>` module:

#!/usr/bin/env python
# encoding: utf-8
# filename: profile.py

import pstats, cProfile

import pyximport
pyximport.install()

import calc_pi

cProfile.runctx("calc_pi.approx_pi()", globals(), locals(), "Profile.prof")

s = pstats.Stats("Profile.prof")
s.strip_dirs().sort_stats("time").print_stats()
.. literalinclude:: ../../examples/tutorial/profiling_tutorial/profile_2.py

We only added two lines, the rest stays completely the same. Alternatively, we could also
manually compile our code into an extension; we wouldn't need to change the
Expand Down

0 comments on commit d39d579

Please sign in to comment.