MCPcopy
hub / github.com/elastic/go-elasticsearch / BenchmarkClientAPI

Function BenchmarkClientAPI

elasticsearch_benchmark_test.go:75–244  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

73}
74
75func BenchmarkClientAPI(b *testing.B) {
76 b.ReportAllocs()
77
78 ctx := context.Background()
79
80 client, err := elasticsearch.New(
81 elasticsearch.WithAddresses("http://localhost:9200"),
82 elasticsearch.WithTransportOptions(elastictransport.WithTransport(newFakeTransport())),
83 )
84 if err != nil {
85 b.Fatalf("ERROR: %s", err)
86 }
87
88 b.Run("InfoRequest{}.Do()", func(b *testing.B) {
89 b.ResetTimer()
90
91 req := esapi.InfoRequest{}
92
93 for i := 0; i < b.N; i++ {
94 if _, err := req.Do(ctx, client); err != nil {
95 b.Errorf("Unexpected error when getting a response: %s", err)
96 }
97 }
98 })
99
100 b.Run("IndexRequest{...}.Do()", func(b *testing.B) {
101 b.ResetTimer()
102 var body strings.Builder
103
104 for i := 0; i < b.N; i++ {
105 docID := strconv.FormatInt(int64(i), 10)
106
107 body.Reset()
108 body.WriteString(`{"foo" : "bar `)
109 body.WriteString(docID)
110 body.WriteString(` " }`)
111
112 req := esapi.IndexRequest{
113 Index: "test",
114 DocumentID: docID,
115 Body: strings.NewReader(body.String()),
116 Refresh: "true",
117 Pretty: true,
118 Timeout: 100,
119 }
120 if _, err := req.Do(ctx, client); err != nil {
121 b.Errorf("Unexpected error when getting a response: %s", err)
122 }
123 }
124 })
125
126 b.Run("Index(...)", func(b *testing.B) {
127 b.ResetTimer()
128 var body strings.Builder
129
130 for i := 0; i < b.N; i++ {
131 docID := strconv.FormatInt(int64(i), 10)
132

Callers

nothing calls this directly

Calls 15

DoMethod · 0.95
IntPtrFunction · 0.92
newFakeTransportFunction · 0.85
RunMethod · 0.45
StringMethod · 0.45
IndexMethod · 0.45
WithDocumentIDMethod · 0.45
WithRefreshMethod · 0.45
WithPrettyMethod · 0.45
WithTimeoutMethod · 0.45
WithContextMethod · 0.45
SearchMethod · 0.45

Tested by

no test coverage detected