This repository was archived by the owner on Aug 8, 2025. It is now read-only.
Improve performance of expo by multiplying previous result#103
Open
whonore wants to merge 1 commit intolitl:masterfrom
Open
Improve performance of expo by multiplying previous result#103whonore wants to merge 1 commit intolitl:masterfrom
whonore wants to merge 1 commit intolitl:masterfrom
Conversation
Member
|
This seems good to me. Just curious, did you run into this because you in your use case the number of retries was very high? |
Author
|
No, I was just browsing the code and noticed that some work was unnecessarily re-done on each loop. I think it's pretty unlikely that anyone would reach enough retries for this to actually make much of a difference, but I figured I'd submit it anyway since it's such a simple change. |
e11e666 to
28552d5
Compare
|
Any chance this can get merged? PR has been open for over a year. |
gaby
approved these changes
Oct 11, 2021
Author
|
Ping? |
frost-nzcr4
suggested changes
Apr 19, 2024
| a = 1 | ||
| while True: | ||
| a = factor * base ** n | ||
| if max_value is None or a < max_value: |
There was a problem hiding this comment.
This max_value condition doesn't work properly with your changes, it needs to be updated a bit, like this, but still 24x faster than the original:
base_n = 1
while True:
a = factor * base_n
if max_value is None or a < max_value:
yield a
base_n *= base28552d5 to
651a453
Compare
frost-nzcr4
approved these changes
Apr 25, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This computes the exponential by multiplying the previous result by
baseinstead of computing it from scratch with**each time, which seems to be about an order of magnitude faster. On my machine the following tests report around 2.63 seconds forexpo_oldand 0.10 forexpo_new.