MCPcopy Index your code
hub / github.com/cloudwego/netpoll / BenchmarkLinkBufferConcurrentReadWrite

Function BenchmarkLinkBufferConcurrentReadWrite

nocopy_linkbuffer_test.go:699–756  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

697}
698
699func BenchmarkLinkBufferConcurrentReadWrite(b *testing.B) {
700 b.StopTimer()
701
702 buf := NewLinkBuffer()
703 var rwTag uint32
704 readMsg := []string{
705 "0123456",
706 "7890123",
707 "4567890",
708 "1234567",
709 "8901234",
710 "5678901",
711 "2345678",
712 "9012345",
713 "6789012",
714 "3456789",
715 }
716 writeMsg := []byte("0123456789")
717
718 // benchmark
719 b.ReportAllocs()
720 b.StartTimer()
721 b.SetParallelism(2) // one read one write
722 b.RunParallel(func(pb *testing.PB) {
723 switch atomic.AddUint32(&rwTag, 1) {
724 case 1:
725 // 1 is write
726 for pb.Next() {
727 p, err := buf.Malloc(80)
728 if err != nil {
729 panic(fmt.Sprintf("malloc error %s", err.Error()))
730 }
731 for i := 0; i < 7; i++ {
732 copy(p[i*10:i*10+10], writeMsg)
733 }
734 buf.MallocAck(70)
735 buf.Flush()
736 }
737 case 2:
738 // 2 is read
739 for pb.Next() {
740 for i := 0; i < 10; {
741 p, err := buf.Next(7)
742 if err == nil {
743 if string(p) != readMsg[i] {
744 panic(fmt.Sprintf("NEXT p[%s] != msg[%s]", p, readMsg[i]))
745 }
746 } else {
747 // No read data, wait for write
748 continue
749 }
750 i++
751 }
752 buf.Release()
753 }
754 }
755 })
756}

Callers

nothing calls this directly

Calls 7

NewLinkBufferFunction · 0.85
ErrorMethod · 0.80
NextMethod · 0.65
MallocMethod · 0.65
MallocAckMethod · 0.65
FlushMethod · 0.65
ReleaseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…