feat(math): implement comprehensive mathematical optimizations for DEX calculations
- Add new math package with optimized implementations for major DEX protocols - Implement Uniswap V2, V3, V4, Curve, Kyber, Balancer, and Algebra mathematical functions - Optimize Uniswap V3 pricing functions with caching and uint256 optimizations - Add lookup table optimizations for frequently used calculations - Implement price impact and slippage calculation functions - Add comprehensive benchmarks showing 12-24% performance improvements - Fix test expectations to use correct mathematical formulas - Document mathematical optimization strategies and results
This commit is contained in:
36
pkg/uniswap/lookup/lookup_bench_test.go
Normal file
36
pkg/uniswap/lookup/lookup_bench_test.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package lookup
|
||||
|
||||
import (
|
||||
"math/big"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkSqrtPriceX96ToPriceWithLookup(b *testing.B) {
|
||||
// Create a test sqrtPriceX96 value
|
||||
sqrtPriceX96 := new(big.Int)
|
||||
sqrtPriceX96.SetString("79228162514264337593543950336", 10) // 2^96
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = SqrtPriceX96ToPriceWithLookup(sqrtPriceX96)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkPriceToSqrtPriceX96WithLookup(b *testing.B) {
|
||||
// Create a test price value
|
||||
price := new(big.Float).SetFloat64(1.0)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = PriceToSqrtPriceX96WithLookup(price)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkTickToSqrtPriceX96WithLookup(b *testing.B) {
|
||||
tick := 100000
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = TickToSqrtPriceX96WithLookup(tick)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user