Skip to content
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

Pre-allocate slice for BigRat() #1

Open
TUSF opened this issue Jan 20, 2018 · 0 comments
Open

Pre-allocate slice for BigRat() #1

TUSF opened this issue Jan 20, 2018 · 0 comments

Comments

@TUSF
Copy link
Owner

TUSF commented Jan 20, 2018

Appending to a slice is slower than allocating beforehand, and directly changing the value of slice[i].

The issue is getting a reliable way to know how big to make the slice. Hypothetically, a slice can only have up to the maximum of the value of int, but allocating that much space may be a waste.

As it turns out, in order to know the exact number of digits a fraction will have, knowing the factors of the base and denominator are needed. The base's factors can be determined when the Formatter is initialized, but for the denominator it might be slow.

May have to do benchmarks to see if it's actually faster, but first need to figure out how to go about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant