-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
53 lines (41 loc) · 959 Bytes
/
benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package httpclient_test
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/halimath/httpclient"
"github.com/mccutchen/go-httpbin/v2/httpbin"
)
func BenchmarkStdLib(b *testing.B) {
app := httpbin.New()
testServer := httptest.NewServer(app.Handler())
defer testServer.Close()
b.ResetTimer()
c := http.Client{}
for i := 0; i < b.N; i++ {
res, err := c.Get(testServer.URL + "/get")
if err != nil {
b.Fatal(err)
}
if res.StatusCode != http.StatusOK {
b.Fatalf("unexpected status code: %d", res.StatusCode)
}
}
}
func BenchmarkHTTPClient(b *testing.B) {
app := httpbin.New()
testServer := httptest.NewServer(app.Handler())
defer testServer.Close()
b.ResetTimer()
c := httpclient.New(
httpclient.WithURLPrefix(testServer.URL),
httpclient.ExpectedStatusCode(http.StatusOK),
)
for i := 0; i < b.N; i++ {
_, err := c.Get(context.Background(), "/get")
if err != nil {
b.Fatal(err)
}
}
}