forked from lox/httpcache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench_test.go
More file actions
39 lines (33 loc) · 865 Bytes
/
bench_test.go
File metadata and controls
39 lines (33 loc) · 865 Bytes
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
package httpcache_test
import (
"fmt"
"net/http"
"net/http/httptest"
"net/http/httputil"
"net/url"
"testing"
"github.com/lox/httpcache"
)
func BenchmarkCachingFiles(b *testing.B) {
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Cache-Control", "max-age=100000")
fmt.Fprintf(w, "cache server payload")
}))
defer backend.Close()
u, err := url.Parse(backend.URL)
if err != nil {
b.Fatal(err)
}
handler := httpcache.NewHandler(httpcache.NewMemoryCache(), httputil.NewSingleHostReverseProxy(u))
handler.Shared = true
cacheServer := httptest.NewServer(handler)
defer cacheServer.Close()
for n := 0; n < b.N; n++ {
client := http.Client{}
resp, err := client.Get(fmt.Sprintf("%s/llamas/%d", cacheServer.URL, n))
if err != nil {
b.Fatal(err)
}
resp.Body.Close()
}
}