forked from elastic/go-elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfasthttp_benchmark_test.go
56 lines (45 loc) · 1.2 KB
/
fasthttp_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
54
55
56
// Licensed to Elasticsearch B.V. under one or more agreements.
// Elasticsearch B.V. licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
package fasthttp_test
import (
"testing"
"github.com/demisto/go-elasticsearch/v8"
"github.com/demisto/go-elasticsearch/v8/_examples/fasthttp"
)
func BenchmarkHTTPClient(b *testing.B) {
b.ReportAllocs()
client, err := elasticsearch.NewDefaultClient()
if err != nil {
b.Fatalf("ERROR: %s", err)
}
b.Run("Info()", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
if res, err := client.Info(); err != nil {
b.Errorf("Unexpected error when getting a response: %s", err)
} else {
res.Body.Close()
}
}
})
}
func BenchmarkFastHTTPClient(b *testing.B) {
b.ReportAllocs()
client, err := elasticsearch.NewClient(
elasticsearch.Config{Transport: &fasthttp.Transport{}},
)
if err != nil {
b.Fatalf("ERROR: %s", err)
}
b.Run("Info()", func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
if res, err := client.Info(); err != nil {
b.Errorf("Unexpected error when getting a response: %s", err)
} else {
res.Body.Close()
}
}
})
}