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

feat: Add public NewFromDecimal which outperforms decimal -> string -> alpacadecimal #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aarjaneiro
Copy link

Should close #7

Note, from my benchmarking:

goos: linux
goarch: amd64
pkg: github.com/alpacahq/alpacadecimal
cpu: AMD Ryzen 9 3900XT 12-Core Processor           
BenchmarkNewFromDecimal
BenchmarkNewFromDecimal/alpacadecimal.Decimal.NewFromDecimal
BenchmarkNewFromDecimal/alpacadecimal.Decimal.NewFromDecimal-24         	47093888	        25.64 ns/op
BenchmarkNewFromDecimal/alpacadecimal.Decimal.RequireFromString
BenchmarkNewFromDecimal/alpacadecimal.Decimal.RequireFromString-24      	 5173086	       233.9 ns/op
BenchmarkNewFromDecimal/alpacadecimal.Decimal.New
BenchmarkNewFromDecimal/alpacadecimal.Decimal.New-24                    	507679633	         2.316 ns/op
PASS

Where NewFromDecimal is the added method, RequireFromString implements the conversion method specified as slow in the linked issue, and New simply creates the alpacadecimal.Decimal in-place (no conversion from decimal.Decimal).

@aarjaneiro aarjaneiro marked this pull request as draft December 10, 2024 18:44
@aarjaneiro aarjaneiro marked this pull request as ready for review December 10, 2024 19:58
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.

Faster way to convert decimal.Decimal to alpacadecimal.Decimal
1 participant