-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
math.big: faster radix_str() #24666
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
Merged
Merged
math.big: faster radix_str() #24666
Conversation
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
Connected to Huly®: V_0.6-23024 |
Can you share the benchmark code? |
Sure :) |
With this slightly modified version of the linked code: import math
import math.big
import benchmark
fn main() {
mut x := u32(math.pow(3, 2))
x = u32(math.pow(4, x))
mut y := big.integer_from_int(5)
mut b := benchmark.start()
for _ in 0 .. 5 {
_ := y.pow(x)
b.measure('y.pow(x) loop')
}
y = y.pow(x)
b.measure('y.pow(x)')
str := y.str()
b.measure('y.str()')
// println(y)
println('5^(4^(3^2)) has ${str.len} digits: ${str[..20]} ... ${str[str.len - 20..]}')
assert str[..20] == '62060698786608744707'
assert str[str.len - 20..] == '92256259918212890625'
} on master:
... while on the branch of this PR:
|
spytheman
reviewed
Jun 8, 2025
spytheman
reviewed
Jun 8, 2025
spytheman
reviewed
Jun 8, 2025
spytheman
reviewed
Jun 8, 2025
In principle, I agree with these suggestions and will make a new push. |
New push contains all suggestions + cap for update: tested against |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Faster conversion of limbs to radix.
Had to split the function into two. They are very similar, as it should be.
Each solves its specific tasks.
Now a larger number of digits is calculated at once.
Performance for radix 10:
o) -current -> 9 times faster;
o) 0.4.10 -> 57 times faster;
Tested against GMP for all radixes in range 2-36.