From 6307c795e10a4845414357137a2efec5842ee248 Mon Sep 17 00:00:00 2001 From: Mihail Stoykov Date: Tue, 15 Oct 2019 12:56:39 +0300 Subject: [PATCH] Reuse some big.Rat in getPlannedRateChanges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit name old time/op new time/op delta GetPlannedRateChanges-4 1.66ms ± 7% 1.34ms ± 2% -19.42% (p=0.008 n=5+5) name old alloc/op new alloc/op delta GetPlannedRateChanges-4 1.22MB ± 0% 0.86MB ± 0% -29.13% (p=0.008 n=5+5) name old allocs/op new allocs/op delta GetPlannedRateChanges-4 51.6k ± 0% 37.2k ± 0% -27.86% (p=0.008 n=5+5) --- lib/executor/variable_arrival_rate.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/executor/variable_arrival_rate.go b/lib/executor/variable_arrival_rate.go index adf6747a7b65..75938aadb88b 100644 --- a/lib/executor/variable_arrival_rate.go +++ b/lib/executor/variable_arrival_rate.go @@ -183,6 +183,9 @@ func (varc VariableArrivalRateConfig) getPlannedRateChanges(segment *lib.Executi rateChanges := []rateChange{} timeFromStart := time.Duration(0) + var tArrivalRate = new(big.Rat) + var tArrivalRateStep = new(big.Rat) + var stepCoef = new(big.Rat) for _, stage := range varc.Stages { stageTargetRate := getScaledArrivalRate(segment, stage.Target.Int64, timeUnit) stageDuration := time.Duration(stage.Duration.Duration) @@ -221,9 +224,12 @@ func (varc VariableArrivalRateConfig) getPlannedRateChanges(segment *lib.Executi break } - tArrivalRate := new(big.Rat).Add( + tArrivalRate.Add( currentRate, - new(big.Rat).Mul(rateDiff, big.NewRat(int64(t), int64(stageDuration))), + tArrivalRateStep.Mul( + rateDiff, + stepCoef.SetFrac64(int64(t), int64(stageDuration)), + ), ) rateChanges = append(rateChanges, rateChange{