Add benchmark for naive endpoint Get so we can measure it

Baseline:

```
BenchmarkGet-12          	  100000	    119635 ns/op	   20110 B/op	     206 allocs/op
BenchmarkWatchHTTP-12    	  100000	     65761 ns/op	    7296 B/op	     139 allocs/op
```

Kubernetes-commit: 2e1506558ac2c82e83cbef469a6e1e845cfc9235
This commit is contained in:
Clayton Coleman 2019-03-21 20:45:19 -04:00 committed by Kubernetes Publisher
parent 0b35c22017
commit dd5dd7ec7e
1 changed files with 35 additions and 0 deletions

View File

@ -1616,6 +1616,41 @@ func TestGet(t *testing.T) {
}
}
func BenchmarkGet(b *testing.B) {
storage := map[string]rest.Storage{}
simpleStorage := SimpleRESTStorage{
item: genericapitesting.Simple{
Other: "foo",
},
}
selfLinker := &setTestSelfLinker{
expectedSet: "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/namespaces/default/simple/id",
name: "id",
namespace: "default",
}
storage["simple"] = &simpleStorage
handler := handleLinker(storage, selfLinker)
server := httptest.NewServer(handler)
defer server.Close()
u := server.URL + "/" + prefix + "/" + testGroupVersion.Group + "/" + testGroupVersion.Version + "/namespaces/default/simple/id"
b.ResetTimer()
for i := 0; i < b.N; i++ {
resp, err := http.Get(u)
if err != nil {
b.Fatalf("unexpected error: %v", err)
}
if resp.StatusCode != http.StatusOK {
b.Fatalf("unexpected response: %#v", resp)
}
if _, err := io.Copy(ioutil.Discard, resp.Body); err != nil {
b.Fatalf("unable to read body")
}
}
b.StopTimer()
}
func TestGetCompression(t *testing.T) {
storage := map[string]rest.Storage{}
simpleStorage := SimpleRESTStorage{