Commit 7419d794 authored by Stefan Behnel's avatar Stefan Behnel

Implement a "--pgo" option for the Jupyter magic that applies profile guided...

Implement a "--pgo" option for the Jupyter magic that applies profile guided optimisation during C compilation.
parent 208eb13a
...@@ -41,6 +41,11 @@ Features added ...@@ -41,6 +41,11 @@ Features added
* The gdb support for Python code (``libpython.py``) was updated to the latest * The gdb support for Python code (``libpython.py``) was updated to the latest
version in CPython 3.7 (git rev 5fe59f8). version in CPython 3.7 (git rev 5fe59f8).
* The IPython/Jupyter magic integration has a new option ``%%cython --pgo`` for profile
guided optimisation. It compiles the cell with PGO settings for the C compiler,
executes it to generate a runtime profile, and then compiles it again using that
profile for C compiler optimisation. Currently only tested with gcc.
* ``len(memoryview)`` can be used in nogil sections to get the size of the * ``len(memoryview)`` can be used in nogil sections to get the size of the
first dimension of a memory view (``shape[0]``). (Github issue #1733) first dimension of a memory view (``shape[0]``). (Github issue #1733)
......
This diff is collapsed.
...@@ -35,6 +35,12 @@ def call(x): ...@@ -35,6 +35,12 @@ def call(x):
return f(*(x,)) return f(*(x,))
""") """)
pgo_cython3_code = cython3_code + py3compat.str_to_unicode("""\
def main():
for _ in range(100): call(5)
main()
""")
if sys.platform == 'win32': if sys.platform == 'win32':
# not using IPython's decorators here because they depend on "nose" # not using IPython's decorators here because they depend on "nose"
...@@ -117,6 +123,13 @@ class TestIPythonMagic(CythonTest): ...@@ -117,6 +123,13 @@ class TestIPythonMagic(CythonTest):
self.assertEqual(ip.user_ns['g'], 2 // 10) self.assertEqual(ip.user_ns['g'], 2 // 10)
self.assertEqual(ip.user_ns['h'], 2 // 10) self.assertEqual(ip.user_ns['h'], 2 // 10)
def test_cython3_pgo(self):
# The Cython cell defines the functions f() and call().
ip.run_cell_magic('cython', '-3 --pgo', pgo_cython3_code)
ip.ex('g = f(10); h = call(10); main()')
self.assertEqual(ip.user_ns['g'], 2.0 / 10.0)
self.assertEqual(ip.user_ns['h'], 2.0 / 10.0)
@skip_win32('Skip on Windows') @skip_win32('Skip on Windows')
def test_extlibs(self): def test_extlibs(self):
code = py3compat.str_to_unicode(""" code = py3compat.str_to_unicode("""
......
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