GeezerVison is showing github.com — gh-110489: Optimise math.ceil for known exact float by hauntsaninja · Pull Request #108801 · python/cpython
Conversation
hauntsaninja
commented
Sep 2, 2023
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
This matches a similar optimisation done by rhettinger for math.floor in #21072
Before:
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=3.14' 'ceil(x)'
20000000 loops, best of 11: 13.3 nsec per loop
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=0.0' 'ceil(x)'
20000000 loops, best of 11: 13.3 nsec per loop
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=-3.14E32' 'ceil(x)'
10000000 loops, best of 11: 35.3 nsec per loop
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=-323452345.14' 'ceil(x)'
10000000 loops, best of 11: 21.8 nsec per loop
After:
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=3.14' 'ceil(x)'
20000000 loops, best of 11: 11.8 nsec per loop
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=0.0' 'ceil(x)'
20000000 loops, best of 11: 11.7 nsec per loop
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=-3.14E32' 'ceil(x)'
10000000 loops, best of 11: 32.7 nsec per loop
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=-323452345.14' 'ceil(x)'
10000000 loops, best of 11: 20.1 nsec per loop
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
if (PyErr_Occurred())
|
|
|
return NULL;
|
|
|
x = PyFloat_AsDouble(number);
|
|
|
if (x == -1.0 && PyErr_Occurred())
|
skirpichev
Sep 2, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be partially covered by tests.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After merging #102523 this should be fixed.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
if (PyFloat_CheckExact(number)) {
|
|
|
x = PyFloat_AS_DOUBLE(number);
|
|
|
}
|
|
|
else
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should follow to the PEP 7 here?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This matches a similar optimisation done for math.floor in
python#21072
Before:
```
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=3.14' 'ceil(x)'
20000000 loops, best of 11: 13.3 nsec per loop
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=0.0' 'ceil(x)'
20000000 loops, best of 11: 13.3 nsec per loop
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=-3.14E32' 'ceil(x)'
10000000 loops, best of 11: 35.3 nsec per loop
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=-323452345.14' 'ceil(x)'
10000000 loops, best of 11: 21.8 nsec per loop
```
After:
```
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=3.14' 'ceil(x)'
20000000 loops, best of 11: 11.8 nsec per loop
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=0.0' 'ceil(x)'
20000000 loops, best of 11: 11.7 nsec per loop
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=-3.14E32' 'ceil(x)'
10000000 loops, best of 11: 32.7 nsec per loop
λ ./python.exe -m timeit -r 11 -s 'from math import ceil' -s 'x=-323452345.14' 'ceil(x)'
10000000 loops, best of 11: 20.1 nsec per loop
```
hauntsaninja
changed the title
Optimise math.ceil for known exact float
gh-110489: Optimise math.ceil for known exact float
Oct 6, 2023
|
Thanks for the review! I'd avoided PEP 7 for consistency with floor, but I just changed both
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot AMD64 Fedora Stable LTO + PGO 3.x has failed when building commit f013b47.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/29/builds/4915) and take a look at the build logs.
- Check if the failure is related to this commit (f013b47) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/all/#builders/29/builds/4915
Failed tests:
- test.test_concurrent_futures.test_shutdown
Failed subtests:
- test_interpreter_shutdown - test.test_concurrent_futures.test_shutdown.ProcessPoolForkProcessPoolShutdownTest.test_interpreter_shutdown
Summary of the results of the build (if available):
==
Click to see traceback logs
Traceback (most recent call last):
File "/home/buildbot/buildarea/3.x.cstratak-fedora-stable-x86_64.lto-pgo/build/Lib/test/test_concurrent_futures/test_shutdown.py", line 50, in test_interpreter_shutdown
self.assertEqual(out.strip(), b"apple")
AssertionError: b'' != b'apple'
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️
Hi! The buildbot AMD64 RHEL8 FIPS Only Blake2 Builtin Hash 3.x has failed when building commit f013b47.
What do you need to do:
- Don't panic.
- Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
- Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/469/builds/6217) and take a look at the build logs.
- Check if the failure is related to this commit (f013b47) or if it is a false positive.
- If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.
You can take a look at the buildbot page here:
https://buildbot.python.org/all/#builders/469/builds/6217
Failed tests:
- test.test_multiprocessing_fork.test_processes
Summary of the results of the build (if available):
==
Click to see traceback logs
remote: Enumerating objects: 18, done.
remote: Counting objects: 5% (1/18)
remote: Counting objects: 11% (2/18)
remote: Counting objects: 16% (3/18)
remote: Counting objects: 22% (4/18)
remote: Counting objects: 27% (5/18)
remote: Counting objects: 33% (6/18)
remote: Counting objects: 38% (7/18)
remote: Counting objects: 44% (8/18)
remote: Counting objects: 50% (9/18)
remote: Counting objects: 55% (10/18)
remote: Counting objects: 61% (11/18)
remote: Counting objects: 66% (12/18)
remote: Counting objects: 72% (13/18)
remote: Counting objects: 77% (14/18)
remote: Counting objects: 83% (15/18)
remote: Counting objects: 88% (16/18)
remote: Counting objects: 94% (17/18)
remote: Counting objects: 100% (18/18)
remote: Counting objects: 100% (18/18), done.
remote: Compressing objects: 5% (1/18)
remote: Compressing objects: 11% (2/18)
remote: Compressing objects: 16% (3/18)
remote: Compressing objects: 22% (4/18)
remote: Compressing objects: 27% (5/18)
remote: Compressing objects: 33% (6/18)
remote: Compressing objects: 38% (7/18)
remote: Compressing objects: 44% (8/18)
remote: Compressing objects: 50% (9/18)
remote: Compressing objects: 55% (10/18)
remote: Compressing objects: 61% (11/18)
remote: Compressing objects: 66% (12/18)
remote: Compressing objects: 72% (13/18)
remote: Compressing objects: 77% (14/18)
remote: Compressing objects: 83% (15/18)
remote: Compressing objects: 88% (16/18)
remote: Compressing objects: 94% (17/18)
remote: Compressing objects: 100% (18/18)
remote: Compressing objects: 100% (18/18), done.
remote: Total 18 (delta 4), reused 6 (delta 0), pack-reused 0
From https://github.com/python/cpython
* branch main -> FETCH_HEAD
Note: switching to 'f013b475047b2e9d377feda9f2e16e5cdef824d7'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at f013b47504 gh-110489: Optimise math.ceil for known exact float (#108801)
Switched to and reset branch 'main'
make: *** [Makefile:2018: buildbottest] Error 5
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Glyphack
pushed a commit
to Glyphack/cpython
that referenced
this pull request
Sep 2, 2024
)
This matches a similar optimisation done for math.floor in
python#21072
Reviewers
rhettinger
Awaiting requested review from rhettinger
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|