Commit 0dffecfa authored by Matus Valo's avatar Matus Valo Committed by GitHub

Docs: Migrate profiling tutorial to pure Python (GH-4311)

parent b2fac63f
# calc_pi.py
def recip_square(i):
return 1. / i ** 2
......
# cython: profile=True
import cython
def recip_square(i: cython.longlong):
return 1. / i ** 2
def approx_pi(n: cython.int = 10000000):
val: cython.double = 0.
k: cython.int
for k in range(1, n + 1):
val += recip_square(k)
return (6 * val) ** .5
# cython: profile=True
# calc_pi.pyx
def recip_square(int i):
return 1. / i ** 2
......
# cython: profile=True
import cython
@cython.cfunc
@cython.inline
@cython.exceptval(-1.0)
def recip_square(i: cython.longlong) -> cython.double:
return 1. / (i * i)
def approx_pi(n: cython.int = 10000000):
val: cython.double = 0.
k: cython.int
for k in range(1, n + 1):
val += recip_square(k)
return (6 * val) ** .5
# cython: profile=True
# calc_pi.pyx
cdef inline double recip_square(int i) except -1.0:
cdef inline double recip_square(long long i) except -1.0:
return 1. / (i * i)
def approx_pi(int n=10000000):
......
# cython: profile=True
import cython
@cython.profile(False)
@cython.cfunc
@cython.inline
@cython.exceptval(-1.0)
def recip_square(i: cython.longlong) -> float:
return 1. / (i * i)
def approx_pi(n: cython.int = 10000000):
val: cython.double = 0.
k: cython.int
for k in range(1, n + 1):
val += recip_square(k)
return (6 * val) ** .5
# cython: profile=True
# calc_pi.pyx
cimport cython
@cython.profile(False)
cdef inline double recip_square(int i) except -1.0:
cdef inline double recip_square(long long i) except -1.0:
return 1. / (i * i)
def approx_pi(int n=10000000):
......
import cython
@cython.profile(False)
def my_often_called_function():
pass
# profile.py
import pstats, cProfile
import calc_pi
......
# profile.py
import pstats, cProfile
import pyximport
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment