diff --git a/docs/mooc/using-compiled-code/profiling-cython.md b/docs/mooc/using-compiled-code/profiling-cython.md index d9f52da..320e87e 100644 --- a/docs/mooc/using-compiled-code/profiling-cython.md +++ b/docs/mooc/using-compiled-code/profiling-cython.md @@ -1,21 +1,23 @@ -!-- Short description: + +# 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 @@ -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 @@ -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 @@ -50,4 +52,3 @@ cimport cython def my_func_not_to_profile(): ... ~~~ -