MCPcopy
hub / github.com/nats-io/nats.go / BenchmarkHeaderDecode

Function BenchmarkHeaderDecode

nats_test.go:1765–1806  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1763}
1764
1765func BenchmarkHeaderDecode(b *testing.B) {
1766 benchmarks := []struct {
1767 name string
1768 header Header
1769 }{
1770 {"Small - 25", Header{
1771 "Msg-ID": []string{"123"}},
1772 },
1773 {"Medium - 141", Header{
1774 "CorrelationID": []string{"123"},
1775 "Msg-ID": []string{"456"},
1776 "X-NATS-Keys": []string{"A", "B", "C"},
1777 "X-Test-Keys": []string{"D", "E", "F"},
1778 }},
1779 {"Large - 368", Header{
1780 "CorrelationID": []string{"123"},
1781 "Msg-ID": []string{"456"},
1782 "X-NATS-Keys": []string{"A", "B", "C"},
1783 "X-Test-Keys": []string{"D", "E", "F"},
1784 "X-A-Long-Header-1": []string{strings.Repeat("A", 100)},
1785 "X-A-Long-Header-2": []string{strings.Repeat("A", 100)},
1786 }},
1787 }
1788 for _, bm := range benchmarks {
1789 b.Run(bm.name, func(b *testing.B) {
1790 b.ReportAllocs()
1791
1792 m := NewMsg("foo")
1793 m.Header = bm.header
1794 hdr, err := m.headerBytes()
1795 if err != nil {
1796 b.Fatalf("Unexpected error: %v", err)
1797 }
1798
1799 for i := 0; i < b.N; i++ {
1800 if _, err := DecodeHeadersMsg(hdr); err != nil {
1801 b.Fatalf("Unexpected error: %v", err)
1802 }
1803 }
1804 })
1805 }
1806}
1807
1808// mockConn simulates a network connection that can fail and recover
1809// after a number of attempts.

Callers

nothing calls this directly

Calls 4

headerBytesMethod · 0.95
NewMsgFunction · 0.85
DecodeHeadersMsgFunction · 0.85
FatalfMethod · 0.80

Tested by

no test coverage detected