Skip to content

Commit 26e1522

Browse files
authored
Modernize if statement using max (#180)
1 parent cad0b97 commit 26e1522

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

internal/hammer/loadtest/throttle.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ func (t *Throttle) Increase() {
4040
t.mu.Lock()
4141
defer t.mu.Unlock()
4242
tokenCount := t.opsPerSecond
43-
delta := float64(tokenCount) * 0.1
44-
if delta < 1 {
45-
delta = 1
46-
}
43+
delta := max(float64(tokenCount)*0.1, 1)
4744
t.opsPerSecond = tokenCount + int(delta)
4845
}
4946

@@ -54,10 +51,7 @@ func (t *Throttle) Decrease() {
5451
if tokenCount <= 1 {
5552
return
5653
}
57-
delta := float64(tokenCount) * 0.1
58-
if delta < 1 {
59-
delta = 1
60-
}
54+
delta := max(float64(tokenCount)*0.1, 1)
6155
t.opsPerSecond = tokenCount - int(delta)
6256
}
6357

0 commit comments

Comments
 (0)