cosmos-sdk/math
Emmanuel T Odeke 3e85182baa
perf: math: optimize and test FormatInt + simplify LegacyNewDecFromStr (#14010)
Optimizes and tests FormatInt by removing inefficient string
concatenation but also making it so much clearer with how one would
express adding thousand separators in natural language. It uses
a combination of strings.Builder whose values can be grown

The performance improvement is stark in every dimension:

```shell
$ benchstat before.txt after3.txt
name                          old time/op    new time/op    delta
DecimalValueRendererFormat-8    4.48µs ± 1%    2.11µs ± 2%  -52.90%  (p=0.000 n=10+10)

name                          old alloc/op   new alloc/op   delta
DecimalValueRendererFormat-8    3.62kB ± 0%    0.78kB ± 0%  -78.59%  (p=0.000 n=10+10)

name                          old allocs/op  new allocs/op  delta
DecimalValueRendererFormat-8      83.0 ± 0%      28.0 ± 0%  -66.27%  (p=0.000 n=10+10)
```

While here, also simplified zero padding for LegacyNewDecFromStr
simply by using strings.Repeat instead of a convoluted
fmt.Sprintf+strconv.Itoa.

Fixes #14008
Fixes #14003

Co-authored-by: Marko <marbar3778@yahoo.com>
2022-11-29 21:00:47 +00:00
..
CHANGELOG.md perf: math: optimize and test FormatInt + simplify LegacyNewDecFromStr (#14010) 2022-11-29 21:00:47 +00:00
dec_internal_test.go refactor: Move sdk.Dec to math package (#12634) 2022-07-20 15:13:45 +00:00
dec_test.go refactor: Move FormatCoins to core (#13306) 2022-10-19 11:21:24 +00:00
dec.go perf: math: optimize and test FormatInt + simplify LegacyNewDecFromStr (#14010) 2022-11-29 21:00:47 +00:00
doc.go refactor!: create math go sub module (#11788) 2022-04-28 14:05:21 -04:00
go.mod build(deps): Bump github.com/stretchr/testify from 1.8.0 to 1.8.1 in /tools/cosmovisor (#13637) 2022-10-24 20:33:20 +02:00
go.sum build(deps): Bump github.com/stretchr/testify from 1.8.0 to 1.8.1 in /tools/cosmovisor (#13637) 2022-10-24 20:33:20 +02:00
int_internal_test.go refactor!: create math go sub module (#11788) 2022-04-28 14:05:21 -04:00
int_test.go perf: math: optimize and test FormatInt + simplify LegacyNewDecFromStr (#14010) 2022-11-29 21:00:47 +00:00
int.go perf: math: optimize and test FormatInt + simplify LegacyNewDecFromStr (#14010) 2022-11-29 21:00:47 +00:00
proto.go refactor: migrate to cosmos/gogoproto (#13070) 2022-09-08 17:27:48 +00:00
sonar-project.properties ci: configure monorepo sonarcloud (#13944) 2022-11-23 10:47:18 +00:00
uint_internal_test.go chore: gofumpt (#11839) 2022-05-19 10:55:27 +02:00
uint_test.go feat: add uint IsNil method (#13381) 2022-09-25 09:19:50 +00:00
uint.go feat: add uint IsNil method (#13381) 2022-09-25 09:19:50 +00:00