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

Optimize NumDigits #356

Merged
merged 5 commits into from
Apr 4, 2024
Merged

Optimize NumDigits #356

merged 5 commits into from
Apr 4, 2024

Commits on Apr 3, 2024

  1. Optimize NumDigits

    Dividing BitLen by math.Log2(10) is what math/big does underneath
    
    Not including the Int64/Uint64 check makes this slightly slower than old method
    
    Included 2 benchmarks, for 10 digit numbers & 100 digit numbers:
    
    -- before
    > go test -bench=NumDigit -run=NumDigit
    goos: linux
    goarch: amd64
    pkg: github.com/shopspring/decimal
    cpu: AMD Ryzen 7 7840U w/ Radeon  780M Graphics
    BenchmarkDecimal_NumDigits10-16     	18317293	        63.87 ns/op
    BenchmarkDecimal_NumDigits100-16    	 3645015	       329.6 ns/op
    
    -- after
    ...
    BenchmarkDecimal_NumDigits10-16     	143781325	         8.488 ns/op
    BenchmarkDecimal_NumDigits100-16    	 5931247	       207.4 ns/op
    serprex committed Apr 3, 2024
    Configuration menu
    Copy the full SHA
    afe2a66 View commit details
    Browse the repository at this point in the history
  2. feedback, fixes bug

    serprex committed Apr 3, 2024
    Configuration menu
    Copy the full SHA
    0a79029 View commit details
    Browse the repository at this point in the history
  3. remove copy, don't need Abs(d.value)

    9007199254740992 converts to float64
    serprex committed Apr 3, 2024
    Configuration menu
    Copy the full SHA
    d538aec View commit details
    Browse the repository at this point in the history

Commits on Apr 4, 2024

  1. %d

    serprex committed Apr 4, 2024
    Configuration menu
    Copy the full SHA
    445700e View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    20bfa00 View commit details
    Browse the repository at this point in the history