MCPcopy
hub / github.com/valyala/fasthttp / BenchmarkCopyZeroAllocOSFileToOSFile

Function BenchmarkCopyZeroAllocOSFileToOSFile

http_timing_test.go:122–152  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

120}
121
122func BenchmarkCopyZeroAllocOSFileToOSFile(b *testing.B) {
123 r, err := os.Open("./README.md")
124 if err != nil {
125 b.Fatal(err)
126 }
127 defer r.Close()
128
129 f, err := os.CreateTemp(os.TempDir(), "test_*")
130 if err != nil {
131 b.Fatal(err)
132 }
133 defer os.Remove(f.Name())
134
135 w, err := os.OpenFile(f.Name(), os.O_WRONLY, 0o444)
136 if err != nil {
137 b.Fatal(err)
138 }
139 defer w.Close()
140
141 b.ResetTimer()
142 for i := 0; i < b.N; i++ {
143 _, err := w.Seek(0, 0)
144 if err != nil {
145 b.Fatal(err)
146 }
147 _, err = copyZeroAlloc(w, r)
148 if err != nil {
149 b.Fatal(err)
150 }
151 }
152}
153
154func BenchmarkCopyZeroAllocOSFileToNetConn(b *testing.B) {
155 ln, err := net.Listen("tcp", "127.0.0.1:0")

Callers

nothing calls this directly

Calls 4

copyZeroAllocFunction · 0.85
OpenMethod · 0.80
RemoveMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…