Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn committed Feb 23, 2024
1 parent 3f290b7 commit 7a10ac9
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tokens/usecase/prices_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package usecase_test

import (
"context"
"testing"

"github.com/osmosis-labs/sqs/domain"
"github.com/osmosis-labs/sqs/domain/cache"
"github.com/osmosis-labs/sqs/router/usecase/routertesting"
"github.com/osmosis-labs/sqs/tokens/usecase/pricing"
)

func BenchmarkGetPrices(b *testing.B) {
// This is a hack to be able to use test suite helpers with the benchmark.
// We need to set testing.T for assertings within the helpers. Otherwise, it would block
s := routertesting.RouterTestHelper{}
s.SetT(&testing.T{})

// Set up mainnet mock state.
router, mainnetState := s.SetupDefaultMainnetRouter()
mainnetUsecase := s.SetupRouterAndPoolsUsecase(router, mainnetState, cache.New(), &cache.RoutesOverwrite{})

// Set up on-chain pricing strategy
pricingStrategy, err := pricing.NewPricingStrategy(domain.ChainPricingSource, mainnetUsecase.Tokens, mainnetUsecase.Router)
s.Require().NoError(err)

b.ResetTimer()

// Run the benchmark
for i := 0; i < b.N; i++ {
// System under test.
_, err := mainnetUsecase.Tokens.GetPrices(context.Background(), routertesting.MainnetDenoms, []string{USDC, USDT}, pricingStrategy)
s.Require().NoError(err)
if err != nil {
b.Errorf("GetPrices returned an error: %v", err)
}
}
}

0 comments on commit 7a10ac9

Please sign in to comment.