Skip to content

Commit dd11a67

Browse files
authored
Add binapi benchmarks (#269)
Signed-off-by: Ondrej Fabry <[email protected]>
1 parent 9c3f9c1 commit dd11a67

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

test/performance/binapi_bench_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package performance
2+
3+
import (
4+
"testing"
5+
6+
"go.fd.io/govpp/binapi/memclnt"
7+
8+
"go.fd.io/govpp/test/vpptesting"
9+
)
10+
11+
func BenchmarkBinapiControlPing(b *testing.B) {
12+
13+
b.Run("1", func(b *testing.B) {
14+
benchBinapiControlPing(b, 1)
15+
})
16+
b.Run("10", func(b *testing.B) {
17+
benchBinapiControlPing(b, 10)
18+
})
19+
b.Run("100", func(b *testing.B) {
20+
benchBinapiControlPing(b, 100)
21+
})
22+
}
23+
24+
func benchBinapiControlPing(b *testing.B, repeatN int) {
25+
test := vpptesting.SetupVPP(b)
26+
ctx := test.Context
27+
28+
c := memclnt.NewServiceClient(test.Conn)
29+
30+
b.ResetTimer()
31+
for i := 0; i < b.N; i++ {
32+
for r := 0; r < repeatN; r++ {
33+
_, err := c.ControlPing(ctx, &memclnt.ControlPing{})
34+
if err != nil {
35+
b.Fatalf("getting version failed: %v", err)
36+
}
37+
}
38+
}
39+
b.StopTimer()
40+
}

test/performance/benchmark_test.go test/performance/stats_bench_test.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ func newStatsClient() adapter.StatsAPI {
2929
}
3030

3131
func BenchmarkStatClientNodeStatsGet(b *testing.B) {
32-
ctx := vpptesting.SetupVPP(b)
33-
defer ctx.TeardownVPP()
32+
vpptesting.SetupVPP(b)
3433

3534
b.Run("1", func(b *testing.B) {
3635
benchStatClientNodeStatsGet(b, 1)
@@ -61,8 +60,7 @@ func benchStatClientNodeStatsGet(b *testing.B, repeatN int) {
6160
}
6261

6362
func BenchmarkStatClientNodeStatsUpdate(b *testing.B) {
64-
ctx := vpptesting.SetupVPP(b)
65-
defer ctx.TeardownVPP()
63+
vpptesting.SetupVPP(b)
6664

6765
b.Run("1", func(b *testing.B) {
6866
benchStatClientNodeStatsLoad(b, 1)
@@ -93,8 +91,7 @@ func benchStatClientNodeStatsLoad(b *testing.B, repeatN int) {
9391
}
9492

9593
func BenchmarkStatClientStatsUpdate(b *testing.B) {
96-
ctx := vpptesting.SetupVPP(b)
97-
defer ctx.TeardownVPP()
94+
vpptesting.SetupVPP(b)
9895

9996
b.Run("1", func(b *testing.B) {
10097
benchStatClientStatsUpdate(b, 1)

0 commit comments

Comments
 (0)