This repository was archived by the owner on Jun 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathbench_test.go
More file actions
112 lines (104 loc) · 2.62 KB
/
bench_test.go
File metadata and controls
112 lines (104 loc) · 2.62 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package tftp // import "pack.ag/tftp"
import (
"fmt"
"io/ioutil"
"strconv"
"strings"
"testing"
)
func BenchmarkGet_random(b *testing.B) {
// random1MB := getTestData(b, "1MB-random")
// text := getTestData(b, "text")
cases := []struct {
name string
url string
response []byte
opts []ClientOpt
}{
{
name: "small data",
url: "tftp://#host#:#port#/file",
response: []byte("the data"),
},
// {
// name: "small data-netascii",
// url: "tftp://#host#:#port#/file",
// response: []byte("the data"),
// opts: []ClientOpt{ClientMode(ModeNetASCII)},
// },
// {
// name: "small-netascii",
// url: "tftp://#host#:#port#/file",
// response: []byte("the\r\x00data with\r\nnewline"),
// opts: []ClientOpt{ClientMode(ModeNetASCII)},
// },
// {
// name: "text",
// url: "tftp://#host#:#port#/file",
// response: text,
// },
// {
// name: "text-netascii-nix",
// url: "tftp://#host#:#port#/file",
// response: text,
// opts: []ClientOpt{ClientMode(ModeNetASCII)},
// },
// {
// name: "text-netascii-windows",
// url: "tftp://#host#:#port#/file",
// response: text,
// opts: []ClientOpt{ClientMode(ModeNetASCII)},
// },
// {
// name: "1MB",
// url: "tftp://#host#:#port#/file",
// response: random1MB,
// },
// {
// name: "1MB, don't send size",
// url: "tftp://#host#:#port#/file",
// response: random1MB,
// },
// {
// name: "1MB-blksize9000",
// url: "tftp://#host#:#port#/file",
// response: random1MB,
// opts: []ClientOpt{ClientBlocksize(9000)},
// },
// {
// name: "1MB-window5",
// url: "tftp://#host#:#port#/file",
// response: random1MB,
// opts: []ClientOpt{ClientWindowsize(5)},
// },
}
for _, c := range cases {
for _, singlePort := range []bool{true, false} {
name := fmt.Sprintf("%s, single port mode: %t", c.name, singlePort)
b.Run(name, func(b *testing.B) {
ip, port, close := newTestServer(b, singlePort, func(w ReadRequest) {
w.WriteSize(int64(len(c.response)))
w.Write([]byte(c.response))
}, nil)
defer close()
url := strings.Replace(c.url, "#host#", ip, 1)
url = strings.Replace(url, "#port#", strconv.Itoa(port), 1)
for i := 0; i < b.N; i++ {
client, err := NewClient(c.opts...)
if err != nil {
b.Fatal(err)
}
file, err := client.Get(url)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
_, err = ioutil.ReadAll(file)
if err != nil {
b.Fatal(err)
}
}
})
}
}
}