Skip to content

Pre-allocate slice for BigRat() #1

Description

@TUSF

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions