From 9eb05c8360a0a8806690b3f2ea2ec3c4bc04c48b Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Thu, 14 May 2026 19:44:19 -0500 Subject: [PATCH] add basic benchmark for most processors --- .../test/artnet-packet-decode_test.go | 12 ++++++ .../test/artnet-packet-encode_test.go | 23 ++++++++++ internal/processor/test/db-query_test.go | 29 +++++++++++++ internal/processor/test/debug-log_test.go | 26 ++++++++++++ internal/processor/test/filter-change_test.go | 26 ++++++++++++ internal/processor/test/filter-expr_test.go | 27 ++++++++++++ internal/processor/test/filter-regex_test.go | 28 +++++++++++++ internal/processor/test/float-parse_test.go | 26 ++++++++++++ internal/processor/test/float-random_test.go | 26 ++++++++++++ internal/processor/test/free-d-create_test.go | 35 ++++++++++++++++ internal/processor/test/free-d-decode_test.go | 14 +++++++ internal/processor/test/free-d-encode_test.go | 22 ++++++++++ .../test/http-response-create_test.go | 28 +++++++++++++ internal/processor/test/int-parse_test.go | 26 ++++++++++++ internal/processor/test/int-random_test.go | 26 ++++++++++++ internal/processor/test/int-scale_test.go | 30 +++++++++++++ internal/processor/test/json-decode_test.go | 25 +++++++++++ internal/processor/test/json-encode_test.go | 25 +++++++++++ internal/processor/test/kv-get_test.go | 42 +++++++++++++------ internal/processor/test/kv-set_test.go | 32 ++++++++++++++ .../test/midi-control_change-create_test.go | 29 +++++++++++++ .../test/midi-message-decode_test.go | 12 ++++++ .../test/midi-message-encode_test.go | 12 ++++++ .../test/midi-message-unpack_test.go | 12 ++++++ .../test/midi-note_off-create_test.go | 29 +++++++++++++ .../test/midi-note_on-create_test.go | 29 +++++++++++++ .../test/midi-program_change-create_test.go | 28 +++++++++++++ .../test/mqtt-message-create_test.go | 30 +++++++++++++ .../test/nats-message-create_test.go | 28 +++++++++++++ .../processor/test/osc-message-create_test.go | 29 +++++++++++++ .../processor/test/osc-message-decode_test.go | 12 ++++++ .../processor/test/osc-message-encode_test.go | 20 +++++++++ internal/processor/test/script-expr_test.go | 27 ++++++++++++ internal/processor/test/script-js_test.go | 27 ++++++++++++ internal/processor/test/script-wasm_test.go | 28 +++++++++++++ .../test/sip-response-audio-create_test.go | 29 +++++++++++++ .../test/sip-response-dtmf-create_test.go | 29 +++++++++++++ internal/processor/test/string-create_test.go | 27 ++++++++++++ internal/processor/test/string-decode_test.go | 25 +++++++++++ internal/processor/test/string-encode_test.go | 25 +++++++++++ internal/processor/test/string-split_test.go | 28 +++++++++++++ .../processor/test/struct-field-get_test.go | 27 ++++++++++++ .../processor/test/struct-method-get_test.go | 27 ++++++++++++ 43 files changed, 1085 insertions(+), 12 deletions(-) diff --git a/internal/processor/test/artnet-packet-decode_test.go b/internal/processor/test/artnet-packet-decode_test.go index 33ea0de..47532d8 100644 --- a/internal/processor/test/artnet-packet-decode_test.go +++ b/internal/processor/test/artnet-packet-decode_test.go @@ -106,3 +106,15 @@ func TestBadArtnetPacketDecode(t *testing.T) { }) } } + +func BenchmarkArtnetPacketDecode(b *testing.B) { + processorInstance := processor.ArtNetPacketDecode{} + payload := []byte{65, 114, 116, 45, 78, 101, 116, 0, 0, 80, 0, 14, 237, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload}) + if err != nil { + b.Fatalf("artnet.packet.decode processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/artnet-packet-encode_test.go b/internal/processor/test/artnet-packet-encode_test.go index 9364a46..3e23ebd 100644 --- a/internal/processor/test/artnet-packet-encode_test.go +++ b/internal/processor/test/artnet-packet-encode_test.go @@ -101,3 +101,26 @@ func TestBadArtnetPacketEncode(t *testing.T) { }) } } + +func BenchmarkArtnetPacketEncode(b *testing.B) { + processorInstance := processor.ArtNetPacketEncode{} + payload := &artnet.ArtDmx{ + ID: []byte{'A', 'r', 't', '-', 'N', 'e', 't', 0x00}, + OpCode: artnet.OpDmx, + ProtVerHi: 0, + ProtVerLo: 14, + Sequence: 237, + Physical: 0, + SubUni: 1, + Net: 0, + Length: 512, + Data: make([]uint8, 512), + } + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload}) + if err != nil { + b.Fatalf("artnet.packet.encode processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/db-query_test.go b/internal/processor/test/db-query_test.go index 5d4c5b9..a8d96fb 100644 --- a/internal/processor/test/db-query_test.go +++ b/internal/processor/test/db-query_test.go @@ -301,3 +301,32 @@ func TestBadDbQuery(t *testing.T) { }) } } + +func BenchmarkDbQuery(b *testing.B) { + registration, ok := processor.ProcessorRegistry["db.query"] + if !ok { + b.Fatalf("db.query processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "db.query", + Params: map[string]any{ + "module": "test", + "query": "SELECT * FROM test;", + }, + }) + + if err != nil { + b.Fatalf("db.query failed to create processor: %s", err) + } + modules := map[string]common.Module{ + "test": test.NewTestDBModule("test"), + } + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: nil, Modules: modules}) + if err != nil { + b.Fatalf("db.query processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/debug-log_test.go b/internal/processor/test/debug-log_test.go index 13c4462..04718e7 100644 --- a/internal/processor/test/debug-log_test.go +++ b/internal/processor/test/debug-log_test.go @@ -118,3 +118,29 @@ func TestBadDebugLog(t *testing.T) { }) } } + +func BenchmarkDebugLog(b *testing.B) { + registration, ok := processor.ProcessorRegistry["debug.log"] + if !ok { + b.Fatalf("debug.log processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "debug.log", + Params: nil, + }) + + if err != nil { + b.Fatalf("debug.log failed to create processor: %s", err) + } + modules := map[string]common.Module{} + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count, Modules: modules}) + if err != nil { + b.Fatalf("debug.log processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/filter-change_test.go b/internal/processor/test/filter-change_test.go index 4d16f65..5045a5d 100644 --- a/internal/processor/test/filter-change_test.go +++ b/internal/processor/test/filter-change_test.go @@ -124,3 +124,29 @@ func TestBadFilterChange(t *testing.T) { }) } } + +func BenchmarkFilterChange(b *testing.B) { + registration, ok := processor.ProcessorRegistry["filter.change"] + if !ok { + b.Fatalf("filter.change processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "filter.change", + Params: nil, + }) + + if err != nil { + b.Fatalf("filter.change failed to create processor: %s", err) + } + modules := map[string]common.Module{} + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count, Modules: modules}) + if err != nil { + b.Fatalf("filter.change processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/filter-expr_test.go b/internal/processor/test/filter-expr_test.go index ae25e78..89b0cd4 100644 --- a/internal/processor/test/filter-expr_test.go +++ b/internal/processor/test/filter-expr_test.go @@ -171,3 +171,30 @@ func TestBadFilterExpr(t *testing.T) { }) } } + +func BenchmarkFilterExpr(b *testing.B) { + registration, ok := processor.ProcessorRegistry["filter.expr"] + if !ok { + b.Fatalf("filter.expr processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "filter.expr", + Params: map[string]any{ + "expression": "Payload % 2 == 0", + }, + }) + + if err != nil { + b.Fatalf("filter.expr failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("filter.expr processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/filter-regex_test.go b/internal/processor/test/filter-regex_test.go index 6f839ab..1e99f54 100644 --- a/internal/processor/test/filter-regex_test.go +++ b/internal/processor/test/filter-regex_test.go @@ -1,6 +1,7 @@ package processor_test import ( + "fmt" "testing" "github.com/jwetzell/showbridge-go/internal/common" @@ -173,3 +174,30 @@ func TestBadFilterRegex(t *testing.T) { }) } } + +func BenchmarkFilterRegex(b *testing.B) { + registration, ok := processor.ProcessorRegistry["filter.regex"] + if !ok { + b.Fatalf("filter.regex processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "filter.regex", + Params: map[string]any{ + "pattern": ".*", + }, + }) + + if err != nil { + b.Fatalf("filter.regex failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: fmt.Sprintf("%d", count)}) + if err != nil { + b.Fatalf("filter.regex processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/float-parse_test.go b/internal/processor/test/float-parse_test.go index 5193a81..6057b62 100644 --- a/internal/processor/test/float-parse_test.go +++ b/internal/processor/test/float-parse_test.go @@ -1,6 +1,7 @@ package processor_test import ( + "fmt" "testing" "github.com/jwetzell/showbridge-go/internal/common" @@ -164,3 +165,28 @@ func TestBadFloatParse(t *testing.T) { }) } } + +func BenchmarkFloatParse(b *testing.B) { + registration, ok := processor.ProcessorRegistry["float.parse"] + if !ok { + b.Fatalf("float.parse processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "float.parse", + Params: nil, + }) + + if err != nil { + b.Fatalf("float.parse failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: fmt.Sprintf("%d", count)}) + if err != nil { + b.Fatalf("float.parse processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/float-random_test.go b/internal/processor/test/float-random_test.go index 52b1abb..874f102 100644 --- a/internal/processor/test/float-random_test.go +++ b/internal/processor/test/float-random_test.go @@ -184,3 +184,29 @@ func TestBadFloatRandom(t *testing.T) { }) } } + +func BenchmarkFloatRandom(b *testing.B) { + registration, ok := processor.ProcessorRegistry["float.random"] + if !ok { + b.Fatalf("float.random processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "float.random", + Params: map[string]any{ + "min": 0.0, + "max": 1.0, + }, + }) + + if err != nil { + b.Fatalf("float.random failed to create processor: %s", err) + } + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: nil}) + if err != nil { + b.Fatalf("float.random processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/free-d-create_test.go b/internal/processor/test/free-d-create_test.go index 9e5ba0a..9391a46 100644 --- a/internal/processor/test/free-d-create_test.go +++ b/internal/processor/test/free-d-create_test.go @@ -877,3 +877,38 @@ func TestBadFreeDCreate(t *testing.T) { }) } } + +func BenchmarkFreeDCreate(b *testing.B) { + registration, ok := processor.ProcessorRegistry["freed.create"] + if !ok { + b.Fatalf("freed.create processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "freed.create", + Params: map[string]any{ + "id": "0", + "pan": "0", + "tilt": "0", + "roll": "0", + "posX": "0", + "posY": "0", + "posZ": "0", + "zoom": "0", + "focus": "0", + }, + }) + + if err != nil { + b.Fatalf("freed.create failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("freed.create processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/free-d-decode_test.go b/internal/processor/test/free-d-decode_test.go index 977c863..717a344 100644 --- a/internal/processor/test/free-d-decode_test.go +++ b/internal/processor/test/free-d-decode_test.go @@ -102,3 +102,17 @@ func TestBadFreeDDecode(t *testing.T) { }) } } + +func BenchmarkFreeDDecode(b *testing.B) { + processorInstance := processor.FreeDDecode{} + payload := []byte{0xd1, 0x01, 0x5a, 0x00, 0x00, 0x2d, 0x00, 0x00, 0xa6, 0x00, 0x00, 0x7f, 0xff, 0x40, 0x7f, 0xff, 0x80, 0x7f, 0xff, + 0xc0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00, 0x00, 50, + } + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload}) + if err != nil { + b.Fatalf("freed.encode processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/free-d-encode_test.go b/internal/processor/test/free-d-encode_test.go index f1b0ac0..bd12b3f 100644 --- a/internal/processor/test/free-d-encode_test.go +++ b/internal/processor/test/free-d-encode_test.go @@ -102,3 +102,25 @@ func TestBadFreeDEncode(t *testing.T) { }) } } + +func BenchmarkFreeDEncode(b *testing.B) { + processorInstance := processor.FreeDEncode{} + payload := freeD.FreeDPosition{ + ID: 1, + Pan: 180, + Tilt: 90, + Roll: -180, + PosX: 131069, + PosY: 131070, + PosZ: 131071, + Zoom: 66051, + Focus: 263430, + } + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload}) + if err != nil { + b.Fatalf("freed.encode processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/http-response-create_test.go b/internal/processor/test/http-response-create_test.go index 0484e7e..d7e69d6 100644 --- a/internal/processor/test/http-response-create_test.go +++ b/internal/processor/test/http-response-create_test.go @@ -157,3 +157,31 @@ func TestBadHTTPResponseCreate(t *testing.T) { }) } } + +func BenchmarkHTTPResponseCreate(b *testing.B) { + registration, ok := processor.ProcessorRegistry["http.response.create"] + if !ok { + b.Fatalf("http.response.create processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "http.response.create", + Params: map[string]any{ + "status": 200, + "bodyTemplate": "Hello, {{.Payload}}!", + }, + }) + + if err != nil { + b.Fatalf("http.response.create failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("http.response.create processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/int-parse_test.go b/internal/processor/test/int-parse_test.go index 4587b0c..8304564 100644 --- a/internal/processor/test/int-parse_test.go +++ b/internal/processor/test/int-parse_test.go @@ -1,6 +1,7 @@ package processor_test import ( + "fmt" "testing" "github.com/jwetzell/showbridge-go/internal/common" @@ -198,3 +199,28 @@ func TestBadIntParse(t *testing.T) { }) } } + +func BenchmarkIntParse(b *testing.B) { + registration, ok := processor.ProcessorRegistry["int.parse"] + if !ok { + b.Fatalf("int.parse processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "int.parse", + Params: nil, + }) + + if err != nil { + b.Fatalf("int.parse failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: fmt.Sprintf("%d", count)}) + if err != nil { + b.Fatalf("int.parse processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/int-random_test.go b/internal/processor/test/int-random_test.go index 863cad6..69dea7a 100644 --- a/internal/processor/test/int-random_test.go +++ b/internal/processor/test/int-random_test.go @@ -195,3 +195,29 @@ func TestBadIntRandom(t *testing.T) { }) } } + +func BenchmarkIntRandom(b *testing.B) { + registration, ok := processor.ProcessorRegistry["int.random"] + if !ok { + b.Fatalf("int.random processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "int.random", + Params: map[string]any{ + "min": 0, + "max": 100, + }, + }) + + if err != nil { + b.Fatalf("int.random failed to create processor: %s", err) + } + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: nil}) + if err != nil { + b.Fatalf("int.random processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/int-scale_test.go b/internal/processor/test/int-scale_test.go index 551b9cd..0b9a5c6 100644 --- a/internal/processor/test/int-scale_test.go +++ b/internal/processor/test/int-scale_test.go @@ -169,3 +169,33 @@ func TestBadIntScale(t *testing.T) { }) } } + +func BenchmarkIntScale(b *testing.B) { + registration, ok := processor.ProcessorRegistry["int.scale"] + if !ok { + b.Fatalf("int.scale processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "int.scale", + Params: map[string]any{ + "inMin": 0, + "inMax": 100, + "outMin": 0, + "outMax": 127, + }, + }) + + if err != nil { + b.Fatalf("int.scale failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count % 100}) + if err != nil { + b.Fatalf("int.scale processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/json-decode_test.go b/internal/processor/test/json-decode_test.go index 2d30099..5d6795b 100644 --- a/internal/processor/test/json-decode_test.go +++ b/internal/processor/test/json-decode_test.go @@ -1,6 +1,7 @@ package processor_test import ( + "fmt" "reflect" "testing" @@ -124,3 +125,27 @@ func TestBadJsonDecode(t *testing.T) { }) } } + +func BenchmarkJsonDecode(b *testing.B) { + registration, ok := processor.ProcessorRegistry["json.decode"] + if !ok { + b.Fatalf("json.decode processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "json.decode", + }) + + if err != nil { + b.Fatalf("json.decode failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: []byte(fmt.Sprintf("{\"key\":%d}", count))}) + if err != nil { + b.Fatalf("json.decode processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/json-encode_test.go b/internal/processor/test/json-encode_test.go index 8996a1c..943d003 100644 --- a/internal/processor/test/json-encode_test.go +++ b/internal/processor/test/json-encode_test.go @@ -1,6 +1,7 @@ package processor_test import ( + "fmt" "slices" "testing" @@ -113,3 +114,27 @@ func TestBadJsonEncode(t *testing.T) { }) } } + +func BenchmarkJsonEncode(b *testing.B) { + registration, ok := processor.ProcessorRegistry["json.encode"] + if !ok { + b.Fatalf("json.encode processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "json.encode", + }) + + if err != nil { + b.Fatalf("json.encode failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: fmt.Sprintf("{\"key\":%d}", count)}) + if err != nil { + b.Fatalf("json.encode processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/kv-get_test.go b/internal/processor/test/kv-get_test.go index 39fc6a2..705c788 100644 --- a/internal/processor/test/kv-get_test.go +++ b/internal/processor/test/kv-get_test.go @@ -58,21 +58,10 @@ func TestGoodKvGet(t *testing.T) { expected any }{ { - name: "basic value", + name: "basic key", params: map[string]any{ "module": "test", "key": "test", - "value": "hello", - }, - payload: "hello", - expected: "test", - }, - { - name: "template value", - params: map[string]any{ - "module": "test", - "key": "test", - "value": "{{.Payload}}", }, payload: "hello", expected: "test", @@ -232,3 +221,32 @@ func TestBadKvGet(t *testing.T) { }) } } + +func BenchmarkKvGet(b *testing.B) { + registration, ok := processor.ProcessorRegistry["kv.get"] + if !ok { + b.Fatalf("kv.get processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "kv.get", + Params: map[string]any{ + "module": "test", + "key": "test", + }, + }) + + if err != nil { + b.Fatalf("kv.get failed to create processor: %s", err) + } + modules := map[string]common.Module{ + "test": test.NewTestKVModule("test"), + } + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: nil, Modules: modules}) + if err != nil { + b.Fatalf("kv.get processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/kv-set_test.go b/internal/processor/test/kv-set_test.go index e026cc3..d85397e 100644 --- a/internal/processor/test/kv-set_test.go +++ b/internal/processor/test/kv-set_test.go @@ -281,3 +281,35 @@ func TestBadKvSet(t *testing.T) { }) } } + +func BenchmarkKvSet(b *testing.B) { + registration, ok := processor.ProcessorRegistry["kv.set"] + if !ok { + b.Fatalf("kv.set processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "kv.set", + Params: map[string]any{ + "module": "test", + "key": "test", + "value": "{{.Payload}}", + }, + }) + + if err != nil { + b.Fatalf("kv.set failed to create processor: %s", err) + } + modules := map[string]common.Module{ + "test": test.NewTestKVModule("test"), + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count, Modules: modules}) + if err != nil { + b.Fatalf("kv.set processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/midi-control_change-create_test.go b/internal/processor/test/midi-control_change-create_test.go index 483af0f..f6505cb 100644 --- a/internal/processor/test/midi-control_change-create_test.go +++ b/internal/processor/test/midi-control_change-create_test.go @@ -159,3 +159,32 @@ func TestBadMIDIControlChangeCreate(t *testing.T) { }) } } + +func BenchmarkMIDIControlChangeCreate(b *testing.B) { + registration, ok := processor.ProcessorRegistry["midi.control_change.create"] + if !ok { + b.Fatalf("midi.control_change.create processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "midi.control_change.create", + Params: map[string]any{ + "channel": "1", + "control": "64", + "value": "127", + }, + }) + + if err != nil { + b.Fatalf("midi.control_change.create failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("midi.control_change.create processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/midi-message-decode_test.go b/internal/processor/test/midi-message-decode_test.go index 80842e1..a52546b 100644 --- a/internal/processor/test/midi-message-decode_test.go +++ b/internal/processor/test/midi-message-decode_test.go @@ -91,3 +91,15 @@ func TestBadMIDIMessageDecode(t *testing.T) { }) } } + +func BenchmarkMIDIMessageDecode(b *testing.B) { + processorInstance := processor.MIDIMessageDecode{} + payload := []byte{0x90, 0x40, 0x7F} + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload}) + if err != nil { + b.Fatalf("midi.message.decode processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/midi-message-encode_test.go b/internal/processor/test/midi-message-encode_test.go index bb97b78..d076c60 100644 --- a/internal/processor/test/midi-message-encode_test.go +++ b/internal/processor/test/midi-message-encode_test.go @@ -89,3 +89,15 @@ func TestBadMIDIMessageEncode(t *testing.T) { }) } } + +func BenchmarkMIDIMessageEncode(b *testing.B) { + processorInstance := processor.MIDIMessageEncode{} + payload := midi.NoteOn(1, 60, 127) + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload}) + if err != nil { + b.Fatalf("midi.message.encode processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/midi-message-unpack_test.go b/internal/processor/test/midi-message-unpack_test.go index ce5b2d4..bb82be1 100644 --- a/internal/processor/test/midi-message-unpack_test.go +++ b/internal/processor/test/midi-message-unpack_test.go @@ -150,3 +150,15 @@ func TestBadMIDIMessageUnpack(t *testing.T) { }) } } + +func BenchmarkMIDIMessageUnpack(b *testing.B) { + processorInstance := processor.MIDIMessageUnpack{} + payload := midi.NoteOn(1, 60, 127) + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload}) + if err != nil { + b.Fatalf("midi.message.unpack processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/midi-note_off-create_test.go b/internal/processor/test/midi-note_off-create_test.go index ebf697b..f159a17 100644 --- a/internal/processor/test/midi-note_off-create_test.go +++ b/internal/processor/test/midi-note_off-create_test.go @@ -158,3 +158,32 @@ func TestBadMIDINoteOffCretea(t *testing.T) { }) } } + +func BenchmarkMIDINoteOffCreate(b *testing.B) { + registration, ok := processor.ProcessorRegistry["midi.note_off.create"] + if !ok { + b.Fatalf("midi.note_off.create processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "midi.note_off.create", + Params: map[string]any{ + "channel": "1", + "note": "60", + "velocity": "100", + }, + }) + + if err != nil { + b.Fatalf("midi.note_off.create failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("midi.note_off.create processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/midi-note_on-create_test.go b/internal/processor/test/midi-note_on-create_test.go index 079a0f0..8269763 100644 --- a/internal/processor/test/midi-note_on-create_test.go +++ b/internal/processor/test/midi-note_on-create_test.go @@ -155,3 +155,32 @@ func TestBadMIDINoteOnCreate(t *testing.T) { }) } } + +func BenchmarkMIDINoteOnCreate(b *testing.B) { + registration, ok := processor.ProcessorRegistry["midi.note_on.create"] + if !ok { + b.Fatalf("midi.note_on.create processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "midi.note_on.create", + Params: map[string]any{ + "channel": "1", + "note": "60", + "velocity": "100", + }, + }) + + if err != nil { + b.Fatalf("midi.note_on.create failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("midi.note_off.create processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/midi-program_change-create_test.go b/internal/processor/test/midi-program_change-create_test.go index 7048b9a..a90c748 100644 --- a/internal/processor/test/midi-program_change-create_test.go +++ b/internal/processor/test/midi-program_change-create_test.go @@ -145,3 +145,31 @@ func TestBadMIDIProgramChangeCreate(t *testing.T) { }) } } + +func BenchmarkMIDIProgramChangeCreate(b *testing.B) { + registration, ok := processor.ProcessorRegistry["midi.program_change.create"] + if !ok { + b.Fatalf("midi.program_change.create processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "midi.program_change.create", + Params: map[string]any{ + "channel": "1", + "program": "60", + }, + }) + + if err != nil { + b.Fatalf("midi.program_change.create failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("midi.program_change.create processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/mqtt-message-create_test.go b/internal/processor/test/mqtt-message-create_test.go index 7c445ed..efffb56 100644 --- a/internal/processor/test/mqtt-message-create_test.go +++ b/internal/processor/test/mqtt-message-create_test.go @@ -240,3 +240,33 @@ func TestBadMQTTMessageCreate(t *testing.T) { }) } } + +func BenchmarkMQTTMessageCreate(b *testing.B) { + registration, ok := processor.ProcessorRegistry["mqtt.message.create"] + if !ok { + b.Fatalf("mqtt.message.create processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "mqtt.message.create", + Params: map[string]any{ + "topic": "test/topic", + "qos": 1, + "retained": true, + "payload": "{{.Payload}}", + }, + }) + + if err != nil { + b.Fatalf("mqtt.message.create failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("mqtt.message.create processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/nats-message-create_test.go b/internal/processor/test/nats-message-create_test.go index e2af2e0..c77725a 100644 --- a/internal/processor/test/nats-message-create_test.go +++ b/internal/processor/test/nats-message-create_test.go @@ -208,3 +208,31 @@ func TestBadNATSMessageCreate(t *testing.T) { }) } } + +func BenchmarkNATSMessageCreate(b *testing.B) { + registration, ok := processor.ProcessorRegistry["nats.message.create"] + if !ok { + b.Fatalf("nats.message.create processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "nats.message.create", + Params: map[string]any{ + "subject": "test.subject", + "payload": "{{.Payload}}", + }, + }) + + if err != nil { + b.Fatalf("nats.message.create failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("nats.message.create processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/osc-message-create_test.go b/internal/processor/test/osc-message-create_test.go index 91cda1d..23ac36a 100644 --- a/internal/processor/test/osc-message-create_test.go +++ b/internal/processor/test/osc-message-create_test.go @@ -400,3 +400,32 @@ func TestBadOSCMessageCreate(t *testing.T) { }) } } + +func BenchmarkOSCMessageCreate(b *testing.B) { + registration, ok := processor.ProcessorRegistry["osc.message.create"] + if !ok { + b.Fatalf("osc.message.create processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "osc.message.create", + Params: map[string]any{ + "address": "/hello", + "args": []any{"{{.Payload}}"}, + "types": "i", + }, + }) + + if err != nil { + b.Fatalf("osc.message.create failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("osc.message.create processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/osc-message-decode_test.go b/internal/processor/test/osc-message-decode_test.go index e28f6d9..ebbaaed 100644 --- a/internal/processor/test/osc-message-decode_test.go +++ b/internal/processor/test/osc-message-decode_test.go @@ -121,3 +121,15 @@ func TestBadOSCMessageDecode(t *testing.T) { }) } } + +func BenchmarkOSCMessageDecode(b *testing.B) { + processorInstance := processor.OSCMessageDecode{} + payload := []byte{47, 116, 101, 115, 116, 0, 0, 0, 44, 105, 0, 0, 0, 0, 0, 42} + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload}) + if err != nil { + b.Fatalf("osc.message.decode processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/osc-message-encode_test.go b/internal/processor/test/osc-message-encode_test.go index e978d74..9a89141 100644 --- a/internal/processor/test/osc-message-encode_test.go +++ b/internal/processor/test/osc-message-encode_test.go @@ -112,3 +112,23 @@ func TestBadOSCMessageEncode(t *testing.T) { }) } } + +func BenchmarkOSCMessageEncode(b *testing.B) { + processorInstance := processor.OSCMessageEncode{} + payload := &osc.OSCMessage{ + Address: "/test", + Args: []osc.OSCArg{ + { + Type: "i", + Value: int32(42), + }, + }, + } + + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: payload}) + if err != nil { + b.Fatalf("osc.message.encode processing failed: %s", err) + } + } +} diff --git a/internal/processor/test/script-expr_test.go b/internal/processor/test/script-expr_test.go index db8c41e..feeeed8 100644 --- a/internal/processor/test/script-expr_test.go +++ b/internal/processor/test/script-expr_test.go @@ -146,3 +146,30 @@ func TestBadScriptExpr(t *testing.T) { }) } } + +func BenchmarkScriptExpr(b *testing.B) { + registration, ok := processor.ProcessorRegistry["script.expr"] + if !ok { + b.Fatalf("script.expr processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "script.expr", + Params: map[string]any{ + "expression": "Payload % 2", + }, + }) + + if err != nil { + b.Fatalf("script.expr failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("script.expr processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/script-js_test.go b/internal/processor/test/script-js_test.go index dbaf180..8c5c202 100644 --- a/internal/processor/test/script-js_test.go +++ b/internal/processor/test/script-js_test.go @@ -221,3 +221,30 @@ func TestBadScriptJS(t *testing.T) { }) } } + +func BenchmarkScriptJS(b *testing.B) { + registration, ok := processor.ProcessorRegistry["script.js"] + if !ok { + b.Fatalf("script.js processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "script.js", + Params: map[string]any{ + "program": "payload = payload + 1", + }, + }) + + if err != nil { + b.Fatalf("script.js failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("script.js processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/script-wasm_test.go b/internal/processor/test/script-wasm_test.go index fcd492a..070f6cf 100644 --- a/internal/processor/test/script-wasm_test.go +++ b/internal/processor/test/script-wasm_test.go @@ -1,6 +1,7 @@ package processor_test import ( + "fmt" "reflect" "testing" @@ -188,3 +189,30 @@ func TestBadScriptWASM(t *testing.T) { }) } } + +func BenchmarkScriptWASM(b *testing.B) { + registration, ok := processor.ProcessorRegistry["script.wasm"] + if !ok { + b.Fatalf("script.wasm processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "script.wasm", + Params: map[string]any{ + "path": "good.wasm", + }, + }) + + if err != nil { + b.Fatalf("script.wasm failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: []byte(fmt.Sprintf("%d", count))}) + if err != nil { + b.Fatalf("script.wasm processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/sip-response-audio-create_test.go b/internal/processor/test/sip-response-audio-create_test.go index 797f68a..0c897e8 100644 --- a/internal/processor/test/sip-response-audio-create_test.go +++ b/internal/processor/test/sip-response-audio-create_test.go @@ -212,3 +212,32 @@ func TestBadSipResponseAudioCreate(t *testing.T) { }) } } + +func BenchmarkSipResponseAudioCreate(b *testing.B) { + registration, ok := processor.ProcessorRegistry["sip.response.audio.create"] + if !ok { + b.Fatalf("sip.response.audio.create processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "sip.response.audio.create", + Params: map[string]any{ + "preWait": 0, + "audioFile": "good.wav", + "postWait": 0, + }, + }) + + if err != nil { + b.Fatalf("sip.response.audio.create failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("sip.response.audio.create processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/sip-response-dtmf-create_test.go b/internal/processor/test/sip-response-dtmf-create_test.go index e3f3059..ce3d384 100644 --- a/internal/processor/test/sip-response-dtmf-create_test.go +++ b/internal/processor/test/sip-response-dtmf-create_test.go @@ -220,3 +220,32 @@ func TestBadSipResponseDTMFCreate(t *testing.T) { }) } } + +func BenchmarkSipResponseDTMFCreate(b *testing.B) { + registration, ok := processor.ProcessorRegistry["sip.response.dtmf.create"] + if !ok { + b.Fatalf("sip.response.dtmf.create processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "sip.response.dtmf.create", + Params: map[string]any{ + "preWait": 0, + "digits": "{{.Payload}}", + "postWait": 0, + }, + }) + + if err != nil { + b.Fatalf("sip.response.dtmf.create failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("sip.response.dtmf.create processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/string-create_test.go b/internal/processor/test/string-create_test.go index 4033950..f72fa8f 100644 --- a/internal/processor/test/string-create_test.go +++ b/internal/processor/test/string-create_test.go @@ -186,3 +186,30 @@ func TestBadStringCreate(t *testing.T) { }) } } + +func BenchmarkStringCreate(b *testing.B) { + registration, ok := processor.ProcessorRegistry["string.create"] + if !ok { + b.Fatalf("string.create processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "string.create", + Params: map[string]any{ + "template": "{{.Payload}}", + }, + }) + + if err != nil { + b.Fatalf("string.create failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: count}) + if err != nil { + b.Fatalf("string.create processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/string-decode_test.go b/internal/processor/test/string-decode_test.go index 8994369..cc72e4f 100644 --- a/internal/processor/test/string-decode_test.go +++ b/internal/processor/test/string-decode_test.go @@ -1,6 +1,7 @@ package processor_test import ( + "fmt" "testing" "github.com/jwetzell/showbridge-go/internal/common" @@ -98,3 +99,27 @@ func TestBadStringDecode(t *testing.T) { }) } } + +func BenchmarkStringDecode(b *testing.B) { + registration, ok := processor.ProcessorRegistry["string.decode"] + if !ok { + b.Fatalf("string.decode processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "string.decode", + }) + + if err != nil { + b.Fatalf("string.decode failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: []byte(fmt.Sprintf("%d", count))}) + if err != nil { + b.Fatalf("string.decode processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/string-encode_test.go b/internal/processor/test/string-encode_test.go index e3926a5..237a41c 100644 --- a/internal/processor/test/string-encode_test.go +++ b/internal/processor/test/string-encode_test.go @@ -1,6 +1,7 @@ package processor_test import ( + "fmt" "slices" "testing" @@ -104,3 +105,27 @@ func TestBadStringEncode(t *testing.T) { }) } } + +func BenchmarkStringEncode(b *testing.B) { + registration, ok := processor.ProcessorRegistry["string.encode"] + if !ok { + b.Fatalf("string.encode processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "string.encode", + }) + + if err != nil { + b.Fatalf("string.encode failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: fmt.Sprintf("%d", count)}) + if err != nil { + b.Fatalf("string.encode processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/string-split_test.go b/internal/processor/test/string-split_test.go index 9eaf7bb..f1f22b4 100644 --- a/internal/processor/test/string-split_test.go +++ b/internal/processor/test/string-split_test.go @@ -1,6 +1,7 @@ package processor_test import ( + "fmt" "slices" "testing" @@ -153,3 +154,30 @@ func TestBadStringSplit(t *testing.T) { }) } } + +func BenchmarkStringSplit(b *testing.B) { + registration, ok := processor.ProcessorRegistry["string.split"] + if !ok { + b.Fatalf("string.split processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "string.split", + Params: map[string]any{ + "separator": ",", + }, + }) + + if err != nil { + b.Fatalf("string.split failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: fmt.Sprintf("%d,%d,%d", count, count, count)}) + if err != nil { + b.Fatalf("string.split processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/struct-field-get_test.go b/internal/processor/test/struct-field-get_test.go index b78ee11..15cea80 100644 --- a/internal/processor/test/struct-field-get_test.go +++ b/internal/processor/test/struct-field-get_test.go @@ -191,3 +191,30 @@ func TestBadStructFieldGet(t *testing.T) { }) } } + +func BenchmarkStructFieldGet(b *testing.B) { + registration, ok := processor.ProcessorRegistry["struct.field.get"] + if !ok { + b.Fatalf("struct.field.get processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "struct.field.get", + Params: map[string]any{ + "name": "Data", + }, + }) + + if err != nil { + b.Fatalf("struct.field.get failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: test.TestStruct{Data: count}}) + if err != nil { + b.Fatalf("struct.field.get processing failed: %s", err) + } + count++ + } +} diff --git a/internal/processor/test/struct-method-get_test.go b/internal/processor/test/struct-method-get_test.go index c45f996..c75be35 100644 --- a/internal/processor/test/struct-method-get_test.go +++ b/internal/processor/test/struct-method-get_test.go @@ -216,3 +216,30 @@ func TestBadStructMethodGet(t *testing.T) { }) } } + +func BenchmarkStructMethodGet(b *testing.B) { + registration, ok := processor.ProcessorRegistry["struct.method.get"] + if !ok { + b.Fatalf("struct.method.get processor not registered") + } + + processorInstance, err := registration.New(config.ProcessorConfig{ + Type: "struct.method.get", + Params: map[string]any{ + "name": "GetData", + }, + }) + + if err != nil { + b.Fatalf("struct.method.get failed to create processor: %s", err) + } + + count := 0 + for b.Loop() { + _, err := processorInstance.Process(b.Context(), common.WrappedPayload{Payload: test.TestStruct{Data: count}}) + if err != nil { + b.Fatalf("struct.method.get processing failed: %s", err) + } + count++ + } +}