Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
fb7cbb83
Commit
fb7cbb83
authored
Jun 16, 2018
by
scoder
Committed by
GitHub
Jun 16, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2357 from gabrieldemarmiesse/test_profiling_tutorial_2
Added tests to "profiling tutorial" part 2
parents
3d291a58
4e052620
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
15 deletions
+16
-15
docs/examples/tutorial/profiling_tutorial/calc_pi_2.pyx
docs/examples/tutorial/profiling_tutorial/calc_pi_2.pyx
+13
-0
docs/src/tutorial/profiling_tutorial.rst
docs/src/tutorial/profiling_tutorial.rst
+3
-15
No files found.
docs/examples/tutorial/profiling_tutorial/calc_pi_2.pyx
0 → 100644
View file @
fb7cbb83
# cython: profile=True
# calc_pi.pyx
def
recip_square
(
int
i
):
return
1.
/
i
**
2
def
approx_pi
(
int
n
=
10000000
):
cdef
double
val
=
0.
cdef
int
k
for
k
in
range
(
1
,
n
+
1
):
val
+=
recip_square
(
k
)
return
(
6
*
val
)
**
.
5
docs/src/tutorial/profiling_tutorial.rst
View file @
fb7cbb83
...
@@ -172,23 +172,11 @@ xrange makes the code run in 5.8 seconds.
...
@@ -172,23 +172,11 @@ xrange makes the code run in 5.8 seconds.
We could optimize a lot in the pure Python version, but since we are interested
We could optimize a lot in the pure Python version, but since we are interested
in Cython, let's move forward and bring this module to Cython. We would do this
in Cython, let's move forward and bring this module to Cython. We would do this
anyway at some time to get the loop run faster. Here is our first Cython version:
:
anyway at some time to get the loop run faster. Here is our first Cython version:
# encoding: utf-8
.. literalinclude:: ../../examples/tutorial/profiling_tutorial/calc_pi_2.pyx
# cython: profile=True
# filename: calc_pi.pyx
def recip_square(int i):
return 1./i**2
def approx_pi(int n=10000000):
cdef double val = 0.
cdef int k
for k in xrange(1,n+1):
val += recip_square(k)
return (6 * val)**.5
Note the
second
line: We have to tell Cython that profiling should be enabled.
Note the
first
line: We have to tell Cython that profiling should be enabled.
This makes the Cython code slightly slower, but without this we would not get
This makes the Cython code slightly slower, but without this we would not get
meaningful output from the cProfile module. The rest of the code is mostly
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.
unchanged, I only typed some variables which will likely speed things up a bit.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment