-
-
Notifications
You must be signed in to change notification settings - Fork 547
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
Avoid underscored arithmetic methods in Python #21448
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Branch: u/jdemeyer/ticket/21448 |
Last 10 new commits:
|
Commit: |
comment:7
This is counterintuitive to me:
I would think that avoiding the additional call to |
comment:8
Rule number 1 of optimizing Python: a method is slow. Almost anything is faster than a method lookup. |
comment:9
And the call of
I don't really have an explanation of why |
comment:10
On the topic of methods being slow, note the difference between:
|
comment:11
I checked the diff and it does what the ticket claims. Just for a complete confirmation, could you post it a new benchmark where the code to be benchmarked is called 100 times in a loop inside a function? Just to make sure that there is no interference from the fact that we are timing at very low granularity. Once confirmed, you can set a positive review on my behalf. Thanks! |
Reviewer: Nicolas M. Thiéry |
comment:13
Thank you for the explanations Jeroen! |
comment:14
I made a benchmark which should be close to possible real-life usage. The conclusion: With With |
comment:16
Note that the benchmark also shows that implementing arithmetic in the category is really slow: With With |
Benchmark |
Changed branch from u/jdemeyer/ticket/21448 to |
comment:17
Attachment: Single-underscore benchmark.ipynb.gz |
In categories, it is better to write
x + y
instead ofx._add_(y)
since the latter can be a lot slower if_add_
is implemented in Cython.We also remove several redundant implementations of
_sub_
where they coincide with the default implementation fromModuleElement
.Depends on #20767
CC: @nthiery
Component: performance
Author: Jeroen Demeyer
Branch/Commit:
ca0f7ba
Reviewer: Nicolas M. Thiéry
Issue created by migration from https://trac.sagemath.org/ticket/21448
The text was updated successfully, but these errors were encountered: