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

Function BenchmarkPublishGobStruct

test/gob_test.go:108–141  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

106}
107
108func BenchmarkPublishGobStruct(b *testing.B) {
109 // stop benchmark for set-up
110 b.StopTimer()
111
112 s := RunServerOnPort(TEST_PORT)
113 defer s.Shutdown()
114
115 ec := NewGobEncodedConn(b)
116 defer ec.Close()
117 ch := make(chan bool)
118
119 me := &person{Name: "derek", Age: 22, Address: "140 New Montgomery St"}
120 me.Children = make(map[string]*person)
121
122 me.Children["sam"] = &person{Name: "sam", Age: 19, Address: "140 New Montgomery St"}
123 me.Children["meg"] = &person{Name: "meg", Age: 17, Address: "140 New Montgomery St"}
124
125 ec.Subscribe("gob_struct", func(p *person) {
126 if !reflect.DeepEqual(p, me) {
127 b.Fatalf("Did not receive the correct struct response")
128 }
129 ch <- true
130 })
131
132 // resume benchmark
133 b.StartTimer()
134
135 for n := 0; n < b.N; n++ {
136 ec.Publish("gob_struct", me)
137 if e := Wait(ch); e != nil {
138 b.Fatal("Did not receive the message")
139 }
140 }
141}

Callers

nothing calls this directly

Calls 7

NewGobEncodedConnFunction · 0.85
FatalfMethod · 0.80
RunServerOnPortFunction · 0.70
WaitFunction · 0.70
SubscribeMethod · 0.65
PublishMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected