Skip to content

Commit

Permalink
Add benchmarks for the code changes in ac16dc9
Browse files Browse the repository at this point in the history
name                            old time/op    new time/op    delta
NewSampleFromTrail/no_failed-8    1.08µs ± 6%    1.02µs ± 6%   ~     (p=0.095 n=5+5)
NewSampleFromTrail/failed-8       2.20µs ± 5%    2.22µs ± 3%   ~     (p=0.841 n=5+5)
name                            old alloc/op   new alloc/op   delta
NewSampleFromTrail/no_failed-8      336B ± 0%      336B ± 0%   ~     (all equal)
NewSampleFromTrail/failed-8         752B ± 0%      752B ± 0%   ~     (all equal)
name                            old allocs/op  new allocs/op  delta
NewSampleFromTrail/no_failed-8      4.00 ± 0%      4.00 ± 0%   ~     (all equal)
NewSampleFromTrail/failed-8         5.00 ± 0%      5.00 ± 0%   ~     (all equal)

name                                         old time/op    new time/op    delta
MeasureAndEmitMetrics/no_responseCallback-8    6.71µs ± 3%    6.82µs ± 2%     ~     (p=0.421 n=5+5)
MeasureAndEmitMetrics/responseCallback-8       8.13µs ± 8%    7.16µs ± 3%  -11.96%  (p=0.008 n=5+5)
name                                         old alloc/op   new alloc/op   delta
MeasureAndEmitMetrics/no_responseCallback-8    1.03kB ± 0%    1.10kB ± 0%   +6.20%  (p=0.008 n=5+5)
MeasureAndEmitMetrics/responseCallback-8       1.80kB ± 0%    1.10kB ± 0%  -39.11%  (p=0.008 n=5+5)
name                                         old allocs/op  new allocs/op  delta
MeasureAndEmitMetrics/no_responseCallback-8      9.00 ± 0%      9.00 ± 0%     ~     (all equal)
MeasureAndEmitMetrics/responseCallback-8         10.0 ± 0%       9.0 ± 0%  -10.00%  (p=0.008 n=5+5)
  • Loading branch information
mstoykov committed Mar 1, 2021
1 parent 1fa3eed commit 7333166
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
86 changes: 86 additions & 0 deletions lib/netext/httpext/transport_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
*
* k6 - a next-generation load testing tool
* Copyright (C) 2021 Load Impact
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package httpext

import (
"context"
"net/http"
"net/url"
"testing"

"github.com/loadimpact/k6/lib"
"github.com/loadimpact/k6/stats"
"github.com/sirupsen/logrus"
)

func BenchmarkMeasureAndEmitMetrics(b *testing.B) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
samples := make(chan stats.SampleContainer, 10)
defer close(samples)
go func() {
for range samples {
}
}()
logger := logrus.New()
logger.Level = logrus.DebugLevel

state := &lib.State{
Options: lib.Options{
RunTags: &stats.SampleTags{},
SystemTags: &stats.DefaultSystemTagSet,
},
Samples: samples,
Logger: logger,
}
t := transport{
state: state,
ctx: ctx,
}

b.ResetTimer()
unfRequest := &unfinishedRequest{
tracer: &Tracer{},
response: &http.Response{
StatusCode: 200,
},
request: &http.Request{
URL: &url.URL{
Host: "example.com",
Scheme: "https",
},
},
}

b.Run("no responseCallback", func(b *testing.B) {
for i := 0; i < b.N; i++ {
t.measureAndEmitMetrics(unfRequest)
}
})

t.responseCallback = func(n int) bool { return true }

b.Run("responseCallback", func(b *testing.B) {
for i := 0; i < b.N; i++ {
t.measureAndEmitMetrics(unfRequest)
}
})
}
30 changes: 30 additions & 0 deletions stats/cloud/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,33 @@ func BenchmarkHTTPPush(b *testing.B) {
})
}
}

func BenchmarkNewSampleFromTrail(b *testing.B) {
tags := generateTags(1, 200)
now := time.Now()
trail := &httpext.Trail{
Blocked: 200 * 100 * time.Millisecond,
Connecting: 200 * 200 * time.Millisecond,
TLSHandshaking: 200 * 300 * time.Millisecond,
Sending: 200 * 400 * time.Millisecond,
Waiting: 500 * time.Millisecond,
Receiving: 600 * time.Millisecond,
EndTime: now,
ConnDuration: 500 * time.Millisecond,
Duration: 150 * 1500 * time.Millisecond,
Tags: tags,
}

b.Run("no failed", func(b *testing.B) {
for s := 0; s < b.N; s++ {
_ = NewSampleFromTrail(trail)
}
})
trail.Failed = null.BoolFrom(true)

b.Run("failed", func(b *testing.B) {
for s := 0; s < b.N; s++ {
_ = NewSampleFromTrail(trail)
}
})
}

0 comments on commit 7333166

Please sign in to comment.