Skip to content

Commit

Permalink
Proof read Profiling Cython
Browse files Browse the repository at this point in the history
  • Loading branch information
mlouhivu committed Sep 5, 2019
1 parent 873767d commit f91cd95
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions docs/mooc/using-compiled-code/profiling-cython.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<!-- Title: Profiling Cython -->

!-- Short description:
<!-- Short description:
By default, Cython code does not show up when using cProfile. In this article we
discuss how to enable profiling of Cython code.
By default, Cython code does not show up when using cProfile. In this article
we discuss how to enable profiling for Cython code.
-->

# Profiling Cython

As the first rule of optimization is to measure performance before starting
any optimization work, one should have made profile of the pure Python code
before starting any Cythonization. However, in the next optimization cycle one
should profile also the Cython code.
before starting any Cythonization. However, in the next optimization cycle
one should profile also the Cython code.

By default, Cython code does not show up in the measurements of cProfile. One
By default, Cython code does not show up in the measurements of cProfile. One
can, however, enable profiling either for the whole module or for individual
functions. In order to enable profiling for the whole function, simply include
a global directive at the top of a file:
functions. In order to enable profiling for the whole function, simply
include a global directive at the top of a file:

~~~ python
# cython: profile=True
Expand All @@ -26,8 +28,8 @@ def myfunc():
...
~~~

In order to enable profiling for a single function, one can include the cython
decorator before function definition:
In order to enable profiling for a single function, one can include the
cython decorator before a function definition:

~~~ python
cimport cython
Expand All @@ -39,8 +41,8 @@ def my_func():

As profiling adds always some overhead, small functions that are called very
frequently can mess up the profile. In these cases one can use the decorator
for disabling profiling for invidual function (in the case profiling is enabled
for the whole module).
for disabling profiling for some functions (if profiling is enabled for the
whole module).

~~~ python
# cython: profile=True
Expand All @@ -50,4 +52,3 @@ cimport cython
def my_func_not_to_profile():
...
~~~

0 comments on commit f91cd95

Please sign in to comment.