-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiterator_benchmark_test.go
102 lines (81 loc) · 1.79 KB
/
iterator_benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//go:build bpftests
// +build bpftests
package gobpfld
import (
"testing"
"github.com/dylandreimerink/gobpfld/bpfsys"
"github.com/dylandreimerink/gobpfld/bpftypes"
)
const mapSize = 100000
var testMap *HashMap
func getTestMap() *HashMap {
if testMap != nil {
return testMap
}
testMap = &HashMap{
AbstractMap: AbstractMap{
Name: MustNewObjName("xdp_stats_map"),
Definition: BPFMapDef{
Type: bpftypes.BPF_MAP_TYPE_ARRAY,
KeySize: 4, // SizeOf(uint32)
ValueSize: 8, // SizeOf(uint64)
MaxEntries: mapSize,
},
},
}
err := testMap.Load()
if err != nil {
panic(err)
}
for i := uint32(0); i < mapSize; i++ {
val := uint64(i * 10)
err = testMap.Set(&i, &val, bpfsys.BPFMapElemAny)
if err != nil {
panic(err)
}
}
return testMap
}
func benchmarkBatchMapIterator(bufSize int, b *testing.B) {
tMap := getTestMap()
b.ResetTimer()
// run the Fib function b.N times
for n := 0; n < b.N; n++ {
iter := batchLookupIterator{
BPFMap: tMap,
BufSize: bufSize,
}
var (
key uint32
value uint64
)
err := iter.Init(&key, &value)
if err != nil {
b.Error(err)
}
var updated bool
for updated, err = iter.Next(); updated && err == nil; updated, err = iter.Next() {
}
if err != nil {
b.Error(err)
}
}
}
func BenchmarkBatchMapIterator16(b *testing.B) {
benchmarkBatchMapIterator(16, b)
}
func BenchmarkBatchMapIterator64(b *testing.B) {
benchmarkBatchMapIterator(64, b)
}
func BenchmarkBatchMapIterator256(b *testing.B) {
benchmarkBatchMapIterator(256, b)
}
func BenchmarkBatchMapIterator1024(b *testing.B) {
benchmarkBatchMapIterator(1024, b)
}
func BenchmarkBatchMapIterator4096(b *testing.B) {
benchmarkBatchMapIterator(4096, b)
}
func BenchmarkBatchMapIterator16384(b *testing.B) {
benchmarkBatchMapIterator(16384, b)
}