Skip to content

Commit 51e8a54

Browse files
committed
Code cleanup
1 parent cb562c1 commit 51e8a54

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

runner/reporter.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ func (r *Reporter) Finalize(stopReason StopReason, total time.Duration) *Report
222222

223223
rep.Fastest = time.Duration(fastestNum * float64(time.Second))
224224
rep.Slowest = time.Duration(slowestNum * float64(time.Second))
225-
rep.Histogram = histogram(&lats, slowestNum, fastestNum)
226-
rep.LatencyDistribution = latencies(&lats)
225+
rep.Histogram = histogram(lats, slowestNum, fastestNum)
226+
rep.LatencyDistribution = latencies(lats)
227227

228228
rep.Details = make([]ResultDetail, len(r.lats))
229229
for i, num := range r.lats {
@@ -240,15 +240,14 @@ func (r *Reporter) Finalize(stopReason StopReason, total time.Duration) *Report
240240
return rep
241241
}
242242

243-
func latencies(latencies *[]float64) []LatencyDistribution {
244-
lats := *latencies
243+
func latencies(latencies []float64) []LatencyDistribution {
245244
pctls := []int{10, 25, 50, 75, 90, 95, 99}
246245
data := make([]float64, len(pctls))
247246
j := 0
248-
for i := 0; i < len(lats) && j < len(pctls); i++ {
249-
current := i * 100 / len(lats)
247+
for i := 0; i < len(latencies) && j < len(pctls); i++ {
248+
current := i * 100 / len(latencies)
250249
if current >= pctls[j] {
251-
data[j] = lats[i]
250+
data[j] = latencies[i]
252251
j++
253252
}
254253
}
@@ -262,8 +261,7 @@ func latencies(latencies *[]float64) []LatencyDistribution {
262261
return res
263262
}
264263

265-
func histogram(latencies *[]float64, slowest, fastest float64) []Bucket {
266-
lats := *latencies
264+
func histogram(latencies []float64, slowest, fastest float64) []Bucket {
267265
bc := 10
268266
buckets := make([]float64, bc+1)
269267
counts := make([]int, bc+1)
@@ -274,8 +272,8 @@ func histogram(latencies *[]float64, slowest, fastest float64) []Bucket {
274272
buckets[bc] = slowest
275273
var bi int
276274
var max int
277-
for i := 0; i < len(lats); {
278-
if lats[i] <= buckets[bi] {
275+
for i := 0; i < len(latencies); {
276+
if latencies[i] <= buckets[bi] {
279277
i++
280278
counts[bi]++
281279
if max < counts[bi] {
@@ -290,7 +288,7 @@ func histogram(latencies *[]float64, slowest, fastest float64) []Bucket {
290288
res[i] = Bucket{
291289
Mark: buckets[i],
292290
Count: counts[i],
293-
Frequency: float64(counts[i]) / float64(len(lats)),
291+
Frequency: float64(counts[i]) / float64(len(latencies)),
294292
}
295293
}
296294
return res

runner/worker.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ func (w *Worker) makeClientStreamingRequest(ctx *context.Context, input []*dynam
164164
counter := 0
165165
// TODO: need to handle and propagate errors
166166
for err == nil {
167-
streamInput := input
168-
inputLen := len(streamInput)
167+
inputLen := len(input)
169168
if input == nil || inputLen == 0 {
170169
// TODO: need to handle error
171170
_, _ = str.CloseAndReceive()
@@ -178,7 +177,7 @@ func (w *Worker) makeClientStreamingRequest(ctx *context.Context, input []*dynam
178177
break
179178
}
180179

181-
payload := streamInput[counter]
180+
payload := input[counter]
182181

183182
var wait <-chan time.Time
184183
if w.config.streamInterval > 0 {
@@ -222,8 +221,7 @@ func (w *Worker) makeBidiRequest(ctx *context.Context, input []*dynamic.Message)
222221

223222
counter := 0
224223

225-
streamInput := input
226-
inputLen := len(streamInput)
224+
inputLen := len(input)
227225

228226
recvDone := make(chan bool)
229227

@@ -252,7 +250,7 @@ func (w *Worker) makeBidiRequest(ctx *context.Context, input []*dynamic.Message)
252250
break
253251
}
254252

255-
payload := streamInput[counter]
253+
payload := input[counter]
256254

257255
var wait <-chan time.Time
258256
if w.config.streamInterval > 0 {

0 commit comments

Comments
 (0)