Skip to content

Commit

Permalink
Reuse some big.Rat in getPlannedRateChanges
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
mstoykov committed Nov 19, 2019
1 parent c04436f commit 6307c79
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/executor/variable_arrival_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 6307c79

Please sign in to comment.