MCPcopy
hub / github.com/coder/websocket / BenchmarkConn

Function BenchmarkConn

conn_test.go:561–668  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

559}
560
561func BenchmarkConn(b *testing.B) {
562 benchCases := []struct {
563 name string
564 mode websocket.CompressionMode
565 }{
566 {
567 name: "disabledCompress",
568 mode: websocket.CompressionDisabled,
569 },
570 {
571 name: "compressContextTakeover",
572 mode: websocket.CompressionContextTakeover,
573 },
574 {
575 name: "compressNoContext",
576 mode: websocket.CompressionNoContextTakeover,
577 },
578 }
579 for _, bc := range benchCases {
580 b.Run(bc.name, func(b *testing.B) {
581 bb, c1, c2 := newConnTest(b, &websocket.DialOptions{
582 CompressionMode: bc.mode,
583 }, &websocket.AcceptOptions{
584 CompressionMode: bc.mode,
585 })
586
587 bb.goEchoLoop(c2)
588
589 bytesWritten := c1.RecordBytesWritten()
590 bytesRead := c1.RecordBytesRead()
591
592 msg := []byte(strings.Repeat("1234", 128))
593 readBuf := make([]byte, len(msg))
594 writes := make(chan struct{})
595 werrs := make(chan error)
596 writerDone := make(chan struct{})
597
598 go func() {
599 defer close(writerDone)
600 for range writes {
601 select {
602 case werrs <- c1.Write(bb.ctx, websocket.MessageText, msg):
603 case <-bb.ctx.Done():
604 return
605 }
606 }
607 }()
608 b.SetBytes(int64(len(msg)))
609 b.ReportAllocs()
610 b.ResetTimer()
611 for i := 0; i < b.N; i++ {
612 select {
613 case writes <- struct{}{}:
614 case <-bb.ctx.Done():
615 b.Fatal(bb.ctx.Err())
616 }
617
618 typ, r, err := c1.Reader(bb.ctx)

Callers

nothing calls this directly

Calls 10

EqualFunction · 0.92
SuccessFunction · 0.92
newConnTestFunction · 0.85
goEchoLoopMethod · 0.80
RecordBytesWrittenMethod · 0.80
RecordBytesReadMethod · 0.80
WriteMethod · 0.45
ReaderMethod · 0.45
ReadMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…