(b *testing.B)
| 73 | } |
| 74 | |
| 75 | func 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 |
nothing calls this directly
no test coverage detected