Skip to content

Commit

Permalink
Speedup Fractional exponentiation, and make a benchmark (#6392)
Browse files Browse the repository at this point in the history
* Speedup Fractional exponentiation, and make a benchmark

* update changelog

---------

Co-authored-by: devbot-wizard <[email protected]>
(cherry picked from commit c54e222)

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
ValarDragon authored and mergify[bot] committed Sep 20, 2023
1 parent 896a4be commit f7a1c39
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Features

* [#6427](https://github.com/osmosis-labs/osmosis/pull/6427) sdk.Coins Mul and Quo helpers in osmoutils
<<<<<<< HEAD
=======
* [#6437](https://github.com/osmosis-labs/osmosis/pull/6437) mutative version for QuoRoundUp

### Misc Improvements

* [#6309](https://github.com/osmosis-labs/osmosis/pull/6309) Add Cosmwasm Pool Queries to Stargate Query
* [#6392](https://github.com/osmosis-labs/osmosis/pull/6392) Speedup fractional exponentiation

### Features

>>>>>>> c54e222f (Speedup Fractional exponentiation, and make a benchmark (#6392))
* [#6416](https://github.com/osmosis-labs/osmosis/pull/6416) feat[CL]: add num initialized ticks query

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion osmomath/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func PowApprox(base Dec, exp Dec, precision Dec) Dec {
// On this line, bigK == i-1.
c, cneg := AbsDifferenceWithSign(a, bigK)
// On this line, bigK == i.
bigK.Set(NewDec(i)) // TODO: O(n) bigint allocation happens
bigK.SetInt64(i)
term.MulMut(c).MulMut(x).QuoMut(bigK)

// a is mutated on absDifferenceWithSign, reset
Expand Down
18 changes: 18 additions & 0 deletions osmomath/pow_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,21 @@ func BenchmarkSqrtPow(b *testing.B) {
}
}
}

func BenchmarkSlowPowCases(b *testing.B) {
tests := []struct {
base Dec
exp Dec
}{
{
base: MustNewDecFromStr("1.99999999999999"),
exp: MustNewDecFromStr("0.1"),
},
}

for i := 0; i < b.N; i++ {
for _, test := range tests {
Pow(test.base, test.exp)
}
}
}

0 comments on commit f7a1c39

Please sign in to comment.