diff --git a/decoder/cri_test.go b/decoder/cri_test.go index 1266914f2..1831e0144 100644 --- a/decoder/cri_test.go +++ b/decoder/cri_test.go @@ -57,3 +57,9 @@ func TestCRIJoined3Lines(t *testing.T) { assert.Equal(t, `{"level":"warn","ts":"2024-05-22T06:39:29.230Z"}\n`, string(row.Log)) assert.Equal(t, false, row.IsPartial) } + +func BenchmarkDecodeCRI(b *testing.B) { + for b.Loop() { + _, _ = DecodeCRI([]byte("2016-10-06T00:17:09.669794202Z stdout P partial content 1\n")) + } +} diff --git a/decoder/csv_test.go b/decoder/csv_test.go index ee1afc365..1a9b1ee32 100644 --- a/decoder/csv_test.go +++ b/decoder/csv_test.go @@ -181,3 +181,11 @@ func TestDecodeToJsonCSV(t *testing.T) { }) } } + +func BenchmarkDecodeCSV(b *testing.B) { + d, _ := NewCSVDecoder(make(map[string]any)) + + for b.Loop() { + _, _ = d.Decode([]byte(`a,b,c`)) + } +} diff --git a/decoder/nginx_test.go b/decoder/nginx_test.go index eb9d2b751..f43cfd5bd 100644 --- a/decoder/nginx_test.go +++ b/decoder/nginx_test.go @@ -153,3 +153,13 @@ func TestNginxError(t *testing.T) { }) } } + +func BenchmarkDecodeNginx(b *testing.B) { + const input = `2022/08/18 09:29:37 [error] 844935#844935: *44934601 upstream timed out (110: Operation timed out) while connecting to upstream, client: 10.125.172.251, server: mpm-youtube-downloader-38.name.tldn, request: "POST /download HTTP/1.1", upstream: "http://10.117.246.15:84/download", host: "mpm-youtube-downloader-38.name.tldn:84"` + "\n" + + d, _ := NewNginxErrorDecoder(nil) + + for b.Loop() { + _, _ = d.Decode([]byte(input)) + } +} diff --git a/decoder/postgres_test.go b/decoder/postgres_test.go index 6b1ad02df..aa4661259 100644 --- a/decoder/postgres_test.go +++ b/decoder/postgres_test.go @@ -22,3 +22,9 @@ func TestPostgres(t *testing.T) { assert.Equal(t, "test_user", root.Dig("user").AsString()) assert.Equal(t, "listening on Unix socket \"/var/run/postgresql/.s.PGSQL.5432\"\n", root.Dig("log").AsString()) } + +func BenchmarkDecodePostgres(b *testing.B) { + for b.Loop() { + _, _ = DecodePostgres([]byte("2021-06-22 16:24:27 GMT [7291] => [3-1] client=test_client,db=test_db,user=test_user LOG: listening on Unix socket \"/var/run/postgresql/.s.PGSQL.5432\"\n")) + } +} diff --git a/decoder/protobuf_test.go b/decoder/protobuf_test.go index 2a3e024a3..37c9f31db 100644 --- a/decoder/protobuf_test.go +++ b/decoder/protobuf_test.go @@ -188,3 +188,23 @@ func TestProtobuf(t *testing.T) { }) } } + +func BenchmarkDecodeProtobuf(b *testing.B) { + const protoMessage = "MyMessage" + + inputData := []byte{10, 13, 10, 9, 109, 121, 95, 115, 116, 114, 105, 110, 103, 16, 123, 18, 14, 10, 4, 115, 116, 114, 49, 10, 4, 115, 116, 114, 50, 16, 1, 24, 10} + + p := map[string]any{ + protoFileParam: "with_imports.proto", + protoMessageParam: protoMessage, + protoImportPathsParam: []any{ + "../testdata/proto", + }, + } + + dec, _ := NewProtobufDecoder(p) + + for b.Loop() { + _, _ = dec.Decode(inputData) + } +} diff --git a/decoder/syslog_rfc3164_test.go b/decoder/syslog_rfc3164_test.go index ba9d29b4f..b642b6ca4 100644 --- a/decoder/syslog_rfc3164_test.go +++ b/decoder/syslog_rfc3164_test.go @@ -164,3 +164,13 @@ func TestSyslogRFC3164(t *testing.T) { }) } } + +func BenchmarkDecodeSyslogRFC3164(b *testing.B) { + const input = "<34>Oct 11 22:14:15 mymachine.example.com myproc[10]: 'myproc' failed on /dev/pts/8\n" + + d, _ := NewSyslogRFC3164Decoder(nil) + + for b.Loop() { + _, _ = d.Decode([]byte(input)) + } +} diff --git a/decoder/syslog_rfc5424_test.go b/decoder/syslog_rfc5424_test.go index 96c68d0fe..c7be49cd3 100644 --- a/decoder/syslog_rfc5424_test.go +++ b/decoder/syslog_rfc5424_test.go @@ -482,3 +482,13 @@ func TestSyslogRFC5424(t *testing.T) { }) } } + +func BenchmarkDecodeSyslogRFC5424(b *testing.B) { + const input = "<165>1 2003-10-11T22:14:15.003Z mymachine.example.com myproc 10 ID47 [exampleSDID@32473 iut=\"3\" eventSource=\"My \\\"Application\\\"\" eventID=\"1011\"] An application event log\n" + + d, _ := NewSyslogRFC5424Decoder(nil) + + for b.Loop() { + _, _ = d.Decode([]byte(input)) + } +}