forked from bmaupin/go-epub
-
Notifications
You must be signed in to change notification settings - Fork 7
/
perf_test.go
56 lines (53 loc) · 1.06 KB
/
perf_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
package epub
import (
"io"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
)
func BenchmarkAddImage_http(b *testing.B) {
filename := "gophercolor16x16.png"
mux := http.NewServeMux()
mux.HandleFunc("/image.png", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
data, err := os.Open(filepath.Join("testdata", filename))
if err != nil {
b.Fatal("cannot open testdata")
}
defer data.Close()
_, err = io.Copy(w, data)
if err != nil {
b.Fatal("cannot copy content")
}
case "HEAD":
w.WriteHeader(http.StatusOK)
}
}))
ts := httptest.NewServer(mux)
defer ts.Close()
e, err := NewEpub("test")
if err != nil {
b.Error(err)
}
for i := 0; i < b.N; i++ {
_, err := e.AddImage(ts.URL+"/image.png", "")
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkAddImage_file(b *testing.B) {
e, err := NewEpub("test")
if err != nil {
b.Error(err)
}
for i := 0; i < b.N; i++ {
_, err := e.AddImage("testdata/gophercolor16x16.png", "")
if err != nil {
b.Fatal(err)
}
}
}