MCPcopy Create free account
hub / github.com/cloudwego/netpoll / BenchmarkConnectionIO

Function BenchmarkConnectionIO

connection_test.go:34–56  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

32)
33
34func BenchmarkConnectionIO(b *testing.B) {
35 dataSize := 1024 * 16
36 writeBuffer := make([]byte, dataSize)
37 rfd, wfd := GetSysFdPairs()
38 rconn, wconn := new(connection), new(connection)
39 rconn.init(&netFD{fd: rfd}, &options{onRequest: func(ctx context.Context, connection Connection) error {
40 read, _ := connection.Reader().Next(dataSize)
41 _ = wconn.Reader().Release()
42 _, _ = connection.Writer().WriteBinary(read)
43 _ = connection.Writer().Flush()
44 return nil
45 }})
46 wconn.init(&netFD{fd: wfd}, new(options))
47
48 b.ResetTimer()
49 b.ReportAllocs()
50 for i := 0; i < b.N; i++ {
51 _, _ = wconn.WriteBinary(writeBuffer)
52 _ = wconn.Flush()
53 _, _ = wconn.Reader().Next(dataSize)
54 _ = wconn.Reader().Release()
55 }
56}
57
58func TestConnectionWrite(t *testing.T) {
59 cycle, caps := 10000, 256

Callers

nothing calls this directly

Calls 8

GetSysFdPairsFunction · 0.85
initMethod · 0.80
NextMethod · 0.65
ReaderMethod · 0.65
ReleaseMethod · 0.65
WriteBinaryMethod · 0.65
WriterMethod · 0.65
FlushMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…