New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speed up SR(Integer/Rational) #24952
Comments
Branch: u/rws/speed_up_sr_integer_ |
This comment has been minimized.
This comment has been minimized.
comment:2
Note the created ex is "numeric" with type MPZ, i.e. Pynac (always) checks if a Python object is an Integer (using New commits:
|
Author: Ralf Stephan |
Commit: |
comment:3
In pure Python, it is 2-3x faster to check sage: def check(x):
....: if hasattr(x,'parent'):
....: return x.parent()
....: return None
sage: def check2(x):
....: try:
....: return x.parent()
....: except AttributeError:
....: return None
sage: z = 5
sage: %timeit check(z)
1000000 loops, best of 3: 205 ns per loop
sage: %timeit check2(z)
10000000 loops, best of 3: 126 ns per loop
sage: z = int(5)
sage: %timeit check(z)
1000000 loops, best of 3: 381 ns per loop
sage: %timeit check2(z)
1000000 loops, best of 3: 889 ns per loop Similar using Cython: sage: %%cython
....: def check(x):
....: if hasattr(x,'parent'):
....: return x.parent()
....: def check2(x):
....: try:
....: return x.parent()
....: except AttributeError:
....: return None
....:
sage: z = 5
sage: %timeit check(z)
10000000 loops, best of 3: 94 ns per loop
sage: %timeit check2(z)
10000000 loops, best of 3: 68.5 ns per loop
sage: z = int(5)
sage: %timeit check(z)
1000000 loops, best of 3: 185 ns per loop
sage: %timeit check2(z)
1000000 loops, best of 3: 395 ns per loop So I am not convinced that removing the |
comment:4
The usage of 'symbolic' should increase so I'll change it back and add the rational case. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
This comment has been minimized.
This comment has been minimized.
comment:7
Thanks. I agree that more thing should implement a |
Reviewer: Travis Scrimshaw |
comment:8
Could this ticket be responsible for this
|
comment:9
Yes, I believe it is. What ticket does this come up on and is it a problem? |
comment:10
Oh, I see, a patchbot failure. |
comment:11
For my own sage-on-gentoo needs I follow the branch were Volker merges stuff. And that one showed up. It took a bit of effort to track a reasonable culprit amongst the tickets merged. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:13
I just replaced the |
comment:14
Should be good. |
Changed branch from u/rws/speed_up_sr_integer_ to |
Before:
Profiling with callgrind shows Python code the main contributor (only 0.4% Pynac), with a big chunk from malloc/free.
Integer
inSR._element_constructor_()
reduces the time to 300nsInteger._symbolic_()
member replacingif (hasattr(x, '_symbolic_')):
withtry: x._symbolic_()
gains 100nsSo this ticket will implement a dedicated
Integer._symbolic_()
that calls helper functions insymbolic/expression.pyx
.Result:
With rational the change is from 4.4µs to 0.6µs.
Component: performance
Author: Ralf Stephan
Branch/Commit:
4997ce4
Reviewer: Travis Scrimshaw
Issue created by migration from https://trac.sagemath.org/ticket/24952
The text was updated successfully, but these errors were encountered: