Skip to content

Commit

Permalink
chore(events): add BenchmarkArgVal
Browse files Browse the repository at this point in the history
Running tool: /home/gg/.goenv/versions/1.22.4/bin/go test -benchmem
-run=^$ -tags ebpf -bench ^BenchmarkArgVal$
github.com/aquasecurity/tracee/pkg/events/parse -benchtime=100000000x

goos: linux
goarch: amd64
pkg: github.com/aquasecurity/tracee/pkg/events/parse
cpu: AMD Ryzen 9 7950X 16-Core Processor
BenchmarkArgVal/int32/valid_args-32        100000000   14.43 ns/op   0 B/op  0 allocs/op
BenchmarkArgVal/int32/invalid_val_type-32  100000000  551.7 ns/op  584 B/op 10 allocs/op
BenchmarkArgVal/int32/not_found_arg-32     100000000  499.2 ns/op  520 B/op 10 allocs/op
PASS
ok  github.com/aquasecurity/tracee/pkg/events/parse  106.538s
  • Loading branch information
geyslan committed Jan 22, 2025
1 parent c585dcb commit b2638f6
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions pkg/events/parse/params_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package parse

import (
"testing"

"github.com/aquasecurity/tracee/types/trace"
)

var args = []trace.Argument{
{
ArgMeta: trace.ArgMeta{
Name: "valid_arg1",
Type: "int",
},
Value: int32(1878),
},
{
ArgMeta: trace.ArgMeta{
Name: "valid_arg2",
Type: "int",
},
Value: int32(1878),
},
{
ArgMeta: trace.ArgMeta{
Name: "invalid_val_type", // in the middle of the list
Type: "int",
},
Value: int64(1878),
},
{
ArgMeta: trace.ArgMeta{
Name: "valid_arg3",
Type: "int",
},
Value: int32(1878),
},
}

func BenchmarkArgVal(b *testing.B) {
b.Run("int32", func(b *testing.B) {
b.Run("valid_args", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, _ = ArgVal[int32](args, "valid_arg1")
_, _ = ArgVal[int32](args, "valid_arg2")
_, _ = ArgVal[int32](args, "valid_arg3")
}
})
b.Run("invalid_val_type", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, _ = ArgVal[int32](args, "invalid_val_type")
}
})
b.Run("not_found_arg", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, _ = ArgVal[int32](args, "not_found_arg")
}
})
})
}

0 comments on commit b2638f6

Please sign in to comment.