benchmarking
This commit is contained in:
parent
f70657bc36
commit
df46339a45
|
@ -82,6 +82,41 @@ func TestProcessProvisions(t *testing.T) {
|
||||||
checkFinalPoolValues(t, pool, sdk.NewRat(initialTotalTokens), cumulativeExpProvs)
|
checkFinalPoolValues(t, pool, sdk.NewRat(initialTotalTokens), cumulativeExpProvs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Benchmark precision
|
||||||
|
func BenchmarkProcessProvisions10000(b *testing.B) {
|
||||||
|
precision = 10000
|
||||||
|
pool := InitialPool()
|
||||||
|
params := DefaultParams()
|
||||||
|
|
||||||
|
var initialTotalTokens int64 = 550000000
|
||||||
|
var cumulativeExpProvs = sdk.ZeroRat()
|
||||||
|
pool.LooseTokens = sdk.NewRat(initialTotalTokens)
|
||||||
|
|
||||||
|
// process the provisions for a year
|
||||||
|
for hr := 0; hr < b.N; hr++ {
|
||||||
|
var expProvisions sdk.Rat
|
||||||
|
_, expProvisions, pool, _ = updateProvisionsBare(pool, params, hr)
|
||||||
|
cumulativeExpProvs = cumulativeExpProvs.Add(expProvisions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkProcessProvisions100000000000(b *testing.B) {
|
||||||
|
precision = 100000000000
|
||||||
|
pool := InitialPool()
|
||||||
|
params := DefaultParams()
|
||||||
|
|
||||||
|
var initialTotalTokens int64 = 550000000
|
||||||
|
var cumulativeExpProvs = sdk.ZeroRat()
|
||||||
|
pool.LooseTokens = sdk.NewRat(initialTotalTokens)
|
||||||
|
|
||||||
|
// process the provisions for a year
|
||||||
|
for hr := 0; hr < b.N; hr++ {
|
||||||
|
var expProvisions sdk.Rat
|
||||||
|
_, expProvisions, pool, _ = updateProvisionsBare(pool, params, hr)
|
||||||
|
cumulativeExpProvs = cumulativeExpProvs.Add(expProvisions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//_________________________________________________________________________________________
|
//_________________________________________________________________________________________
|
||||||
////////////////////////////////HELPER FUNCTIONS BELOW/////////////////////////////////////
|
////////////////////////////////HELPER FUNCTIONS BELOW/////////////////////////////////////
|
||||||
|
|
||||||
|
@ -94,10 +129,7 @@ func checkFinalPoolValues(t *testing.T, pool Pool, initialTotalTokens, cumulativ
|
||||||
// Processes provisions are added to the pool correctly every hour
|
// Processes provisions are added to the pool correctly every hour
|
||||||
// Returns expected Provisions, expected Inflation, and pool, to help with cumulative calculations back in main Tests
|
// Returns expected Provisions, expected Inflation, and pool, to help with cumulative calculations back in main Tests
|
||||||
func updateProvisions(t *testing.T, pool Pool, params Params, hr int) (sdk.Rat, sdk.Rat, Pool) {
|
func updateProvisions(t *testing.T, pool Pool, params Params, hr int) (sdk.Rat, sdk.Rat, Pool) {
|
||||||
expInflation := pool.NextInflation(params)
|
expInflation, expProvisions, pool, startTotalSupply := updateProvisionsBare(pool, params, hr)
|
||||||
expProvisions := expInflation.Mul(pool.TokenSupply()).Quo(hrsPerYrRat)
|
|
||||||
startTotalSupply := pool.TokenSupply()
|
|
||||||
pool = pool.ProcessProvisions(params)
|
|
||||||
|
|
||||||
//check provisions were added to pool
|
//check provisions were added to pool
|
||||||
require.True(sdk.RatEq(t, startTotalSupply.Add(expProvisions), pool.TokenSupply()))
|
require.True(sdk.RatEq(t, startTotalSupply.Add(expProvisions), pool.TokenSupply()))
|
||||||
|
@ -105,6 +137,14 @@ func updateProvisions(t *testing.T, pool Pool, params Params, hr int) (sdk.Rat,
|
||||||
return expInflation, expProvisions, pool
|
return expInflation, expProvisions, pool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateProvisionsBare(pool Pool, params Params, hr int) (sdk.Rat, sdk.Rat, Pool, sdk.Rat) {
|
||||||
|
expInflation := pool.NextInflation(params)
|
||||||
|
expProvisions := expInflation.Mul(pool.TokenSupply()).Quo(hrsPerYrRat)
|
||||||
|
startTotalSupply := pool.TokenSupply()
|
||||||
|
pool = pool.ProcessProvisions(params)
|
||||||
|
return expInflation, expProvisions, pool, startTotalSupply
|
||||||
|
}
|
||||||
|
|
||||||
// Checks that The inflation will correctly increase or decrease after an update to the pool
|
// Checks that The inflation will correctly increase or decrease after an update to the pool
|
||||||
// nolint: gocyclo
|
// nolint: gocyclo
|
||||||
func checkInflation(t *testing.T, pool Pool, previousInflation, updatedInflation sdk.Rat, msg string) {
|
func checkInflation(t *testing.T, pool Pool, previousInflation, updatedInflation sdk.Rat, msg string) {
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (p Pool) bondedTokensToLoose(bondedTokens sdk.Rat) Pool {
|
||||||
//_______________________________________________________________________
|
//_______________________________________________________________________
|
||||||
// Inflation
|
// Inflation
|
||||||
|
|
||||||
const precision = 100000000000 // increased to this precision for accuracy
|
var precision int64 = 100000000000 // increased to this precision for accuracy
|
||||||
var hrsPerYrRat = sdk.NewRat(8766) // as defined by a julian year of 365.25 days
|
var hrsPerYrRat = sdk.NewRat(8766) // as defined by a julian year of 365.25 days
|
||||||
|
|
||||||
// process provisions for an hour period
|
// process provisions for an hour period
|
||||||
|
|
Loading…
Reference in New Issue