Skip to content

math.big: faster integer_from_radix() #24674

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 1 commit into from
Jun 9, 2025
Merged

Conversation

tankf33der
Copy link
Contributor

@tankf33der tankf33der commented Jun 8, 2025

Lets make integer_from_radix() faster too.
Use the same mechanism to calculate more digits at once as in radix_str().

o) ~10 times faster
o) these two functions tested together in 1M loop against gmp.

Copy link

Connected to Huly®: V_0.6-23031

@enghitalo
Copy link
Contributor

enghitalo commented Jun 9, 2025

Can you, please, provide the benchmark code?

@tankf33der
Copy link
Contributor Author

Cam you, please, provide the benchmark code?

Sure.
http://pb1n.de/?9655c8

Again code without benchmarks. 180k+ digit.
I compiled in -prod and used util 'time'.

@spytheman
Copy link
Member

It is indeed a lot faster, for very big numbers:

#0 10:42:40 ^ master ~/v>./v -o xold x.v
#0 10:42:46 ^ master ~/v>git switch -
Switched to branch 'from_radix'
#0 10:42:48 ^ from_radix ~/v>./v -o xnew x.v
#0 10:42:51 ^ from_radix ~/v>
#0 10:42:52 ^ from_radix ~/v>
#0 10:42:53 ^ from_radix ~/v>ls -larS xold xnew
-rwxrwxr-x 1 delian delian 802745 Jun  9 10:42 xold
-rwxrwxr-x 1 delian delian 806954 Jun  9 10:42 xnew
#0 10:42:57 ^ from_radix ~/v>
#0 10:42:58 ^ from_radix ~/v>time ./xold
 SPENT 20503.204 ms in integer_from_string

real    0m20.507s
user    0m20.441s
sys     0m0.036s
#0 10:43:24 ^ from_radix ~/v>time ./xnew
 SPENT  2264.233 ms in integer_from_string

real    0m2.269s
user    0m2.263s
sys     0m0.004s
#0 10:43:30 ^ from_radix ~/v>

Excellent work.

@spytheman spytheman merged commit e8fe334 into vlang:master Jun 9, 2025
70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants