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
c3e04d0f
Commit
c3e04d0f
authored
Dec 31, 2014
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Line profiler testing.
parent
931ca4d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
tests/run/line_profile_test.srctree
tests/run/line_profile_test.srctree
+51
-0
No files found.
tests/run/line_profile_test.srctree
0 → 100644
View file @
c3e04d0f
PYTHON setup.py build_ext --inplace
PYTHON test_profile.py
######## setup.py ###########
from distutils.extension import Extension
from distutils.core import setup
from Cython.Build import cythonize
from Cython.Compiler.Options import directive_defaults
directive_defaults['linetrace'] = True
directive_defaults['binding'] = True
extensions = [
Extension("collatz", ["collatz.pyx"], define_macros=[('CYTHON_TRACE', '1')])
]
setup(
ext_modules = cythonize(extensions)
)
######## test_profile.py ###########
from collatz import collatz
try:
import line_profiler
except ImportError:
print "No line profiler, skipping test."
profile = line_profiler.LineProfiler(collatz)
profile.runcall(collatz, 19)
profile.print_stats()
stats = profile.get_stats()
assert len(stats.timings) > 0, "No profile stats."
for key, timings in stats.timings.items():
if key[-1] == 'collatz':
assert len(timings) > 0
break
else:
raise ValueError, "No stats for collatz."
######## collatz.pyx ###########
def collatz(n):
while n > 1:
if n % 2 == 0:
n //= 2
else:
n = 3*n+1
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