-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
handler_test.go
34 lines (31 loc) · 738 Bytes
/
handler_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
package requests_test
import (
"context"
"fmt"
"net/http"
"os"
"path/filepath"
"testing"
"github.com/carlmjohnson/requests"
"github.com/carlmjohnson/requests/internal/be"
)
func BenchmarkBuilder_ToFile(b *testing.B) {
d, err := os.MkdirTemp("", "to_file_*")
be.NilErr(b, err)
b.Cleanup(func() {
os.RemoveAll(d)
})
tmpFiles := make([]string, b.N)
for n := 0; n < b.N; n++ {
tmpFile := filepath.Join(d, fmt.Sprintf("10mb-%d.test", n))
tmpFiles[n] = tmpFile
}
b.ResetTimer()
for n := 0; n < b.N; n++ {
err = requests.URL("http://speedtest-nyc1.digitalocean.com/10mb.test").
Client(&http.Client{Transport: http.DefaultTransport}).
ToFile(tmpFiles[n]).
Fetch(context.Background())
be.NilErr(b, err)
}
}