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

Function BenchmarkCopyZeroAllocOSFileToNetConn

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

Source from the content-addressed store, hash-verified

152}
153
154func BenchmarkCopyZeroAllocOSFileToNetConn(b *testing.B) {
155 ln, err := net.Listen("tcp", "127.0.0.1:0")
156 if err != nil {
157 b.Fatal(err)
158 }
159
160 addr := ln.Addr().String()
161 defer ln.Close()
162
163 done := make(chan struct{})
164 defer close(done)
165
166 go func() {
167 conn, err := ln.Accept()
168 if err != nil {
169 b.Error(err)
170 return
171 }
172 defer conn.Close()
173 for {
174 select {
175 case <-done:
176 return
177 default:
178 _, err := io.Copy(io.Discard, conn)
179 if err != nil {
180 b.Error(err)
181 return
182 }
183 }
184 }
185 }()
186
187 conn, err := net.Dial("tcp", addr)
188 if err != nil {
189 b.Fatal(err)
190 }
191 defer conn.Close()
192
193 file, err := os.Open("./README.md")
194 if err != nil {
195 b.Fatal(err)
196 }
197 defer file.Close()
198
199 b.ResetTimer()
200 for i := 0; i < b.N; i++ {
201 if _, err := copyZeroAlloc(conn, file); err != nil {
202 b.Fatal(err)
203 }
204 }
205}
206
207func BenchmarkCopyZeroAllocNetConnToOSFile(b *testing.B) {
208 data, err := os.ReadFile("./README.md")

Callers

nothing calls this directly

Calls 8

copyZeroAllocFunction · 0.85
OpenMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.45
AddrMethod · 0.45
AcceptMethod · 0.45
ErrorMethod · 0.45
DialMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…