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 NewFromString a bit #198

Merged
merged 2 commits into from
Jan 10, 2021
Merged

optimize NewFromString a bit #198

merged 2 commits into from
Jan 10, 2021

Conversation

nknordeen
Copy link
Contributor

Hi, while looking through the code, I noticed a string split being used and thought I'd make a pr for optimizing the parsing of a string a bit.

original:

goos: darwin
goarch: amd64
pkg: github.com/shopspring/decimal
BenchmarkDecimal_NewFromString_large_number
BenchmarkDecimal_NewFromString_large_number-12    	   23740	     50176 ns/op	   14400 B/op	     432 allocs/op
PASS

goos: darwin
goarch: amd64
pkg: github.com/shopspring/decimal
BenchmarkDecimal_NewFromString
BenchmarkDecimal_NewFromString-12    	   48504	     24745 ns/op	    8064 B/op	     360 allocs/op
PASS

new numbers

for large numbers:

goos: darwin
goarch: amd64
pkg: github.com/shopspring/decimal
BenchmarkDecimal_NewFromString_large_number
BenchmarkDecimal_NewFromString_large_number-12    	   27516	     43336 ns/op	   12096 B/op	     360 allocs/op
PASS

optimization for smaller numbers:

goos: darwin
goarch: amd64
pkg: github.com/shopspring/decimal
BenchmarkDecimal_NewFromString
BenchmarkDecimal_NewFromString-12    	  102325	     11520 ns/op	    3456 B/op	     216 allocs/op
PASS

@njason
Copy link
Member

njason commented Jan 10, 2021

LGTM, thanks!

@njason njason merged commit 0cada0b into shopspring:master Jan 10, 2021
@mwoss
Copy link
Member

mwoss commented Jan 10, 2021

LGTM too, thanks @nknordeen .
There is a space for simplification of branching in this init method, but we can work on this later. :)

connyay added a commit to connyay/drio that referenced this pull request Oct 15, 2021
Kinda interested in the perf improvements: shopspring/decimal#198
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