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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
e3651b15
Commit
e3651b15
authored
Jun 16, 2018
by
scoder
Committed by
GitHub
Jun 16, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2360 from gabrieldemarmiesse/test_profiling_tutorial_5
Added tests to "profiling tutorial" part 5
parents
ce64b3b6
ad096ace
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
17 deletions
+18
-17
docs/examples/tutorial/profiling_tutorial/calc_pi_4.pyx
docs/examples/tutorial/profiling_tutorial/calc_pi_4.pyx
+16
-0
docs/src/tutorial/profiling_tutorial.rst
docs/src/tutorial/profiling_tutorial.rst
+2
-17
No files found.
docs/examples/tutorial/profiling_tutorial/calc_pi_4.pyx
0 → 100644
View file @
e3651b15
# cython: profile=True
# calc_pi.pyx
cimport
cython
@
cython
.
profile
(
False
)
cdef
inline
double
recip_square
(
int
i
):
return
1.
/
(
i
*
i
)
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 @
e3651b15
...
...
@@ -238,24 +238,9 @@ That bought us another 1.8 seconds. Not the dramatic change we could have
expected. And why is recip_square still in this table; it is supposed to be
inlined, isn't it? The reason for this is that Cython still generates profiling code
even if the function call is eliminated. Let's tell it to not
profile recip_square any more; we couldn't get the function to be much faster anyway:
:
profile recip_square any more; we couldn't get the function to be much faster anyway:
# encoding: utf-8
# cython: profile=True
# filename: calc_pi.pyx
cimport cython
@cython.profile(False)
cdef inline double recip_square(int i):
return 1./(i*i)
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
.. literalinclude:: ../../examples/tutorial/profiling_tutorial/calc_pi_4.pyx
Running this shows an interesting result:
...
...
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