MCPcopy Create free account
hub / github.com/valyala/fasthttp / BenchmarkCopyZeroAllocNetConnToOSFile

Function BenchmarkCopyZeroAllocNetConnToOSFile

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

Source from the content-addressed store, hash-verified

205}
206
207func BenchmarkCopyZeroAllocNetConnToOSFile(b *testing.B) {
208 data, err := os.ReadFile("./README.md")
209 if err != nil {
210 b.Fatal(err)
211 }
212
213 ln, err := net.Listen("tcp", "127.0.0.1:0")
214 if err != nil {
215 b.Fatal(err)
216 }
217
218 addr := ln.Addr().String()
219 defer ln.Close()
220
221 done := make(chan struct{})
222 defer close(done)
223
224 writeDone := make(chan struct{})
225 go func() {
226 for {
227 select {
228 case <-done:
229 return
230 default:
231 conn, err := ln.Accept()
232 if err != nil {
233 b.Error(err)
234 return
235 }
236 _, err = conn.Write(data)
237 if err != nil {
238 b.Error(err)
239 }
240 conn.Close()
241 writeDone <- struct{}{}
242 }
243 }
244 }()
245
246 tmp, err := os.CreateTemp(os.TempDir(), "test_*")
247 if err != nil {
248 b.Fatal(err)
249 }
250 defer os.Remove(tmp.Name())
251
252 file, err := os.OpenFile(tmp.Name(), os.O_WRONLY, 0o444)
253 if err != nil {
254 b.Fatal(err)
255 }
256 defer file.Close()
257
258 conn, err := net.Dial("tcp", addr)
259 if err != nil {
260 b.Fatal(err)
261 }
262 defer conn.Close()
263
264 b.ResetTimer()

Callers

nothing calls this directly

Calls 9

copyZeroAllocFunction · 0.85
RemoveMethod · 0.80
CloseMethod · 0.65
WriteMethod · 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…