Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions decoder/cri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
19 changes: 19 additions & 0 deletions decoder/csv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,22 @@ func TestDecodeToJsonCSV(t *testing.T) {
})
}
}

func BenchmarkDecodeCSV_Decode(b *testing.B) {
d, _ := NewCSVDecoder(make(map[string]any))

for b.Loop() {
_, _ = d.Decode([]byte(`a,b,c`))
}
}
Comment thread
kirillov6 marked this conversation as resolved.
Outdated

func BenchmarkCSVDecoder_DecodeToJsonCSV(b *testing.B) {
d, _ := NewCSVDecoder(make(map[string]any))

root := insaneJSON.Spawn()
defer insaneJSON.Release(root)

for b.Loop() {
_ = d.DecodeToJson(root, []byte(`a,b,c`))
}
}
24 changes: 24 additions & 0 deletions decoder/nginx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package decoder
import (
"testing"

insaneJSON "github.com/ozontech/insane-json"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -153,3 +154,26 @@ func TestNginxError(t *testing.T) {
})
}
}

func BenchmarkNginxErrorDecoder_Decode(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))
}
}

func BenchmarkNginxErrorDecoder_DecodeToJson(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)

root := insaneJSON.Spawn()
defer insaneJSON.Release(root)

for b.Loop() {
_ = d.DecodeToJson(root, []byte(input))
}
}
9 changes: 9 additions & 0 deletions decoder/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,12 @@ 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 BenchmarkDecodePostgresToJson(b *testing.B) {
root := insaneJSON.Spawn()
defer insaneJSON.Release(root)

for b.Loop() {
_ = DecodePostgresToJson(root, []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"))
}
}
43 changes: 43 additions & 0 deletions decoder/protobuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,46 @@ func TestProtobuf(t *testing.T) {
})
}
}

func BenchmarkProtobufDecoder_Decode(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)
}
}

func BenchmarkProtobufDecoder_DecodeToJson(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)

root := insaneJSON.Spawn()
defer insaneJSON.Release(root)

for b.Loop() {
_ = dec.DecodeToJson(root, inputData)
}
}
24 changes: 24 additions & 0 deletions decoder/syslog_rfc3164_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package decoder
import (
"testing"

insaneJSON "github.com/ozontech/insane-json"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -164,3 +165,26 @@ func TestSyslogRFC3164(t *testing.T) {
})
}
}

func BenchmarkSyslogRFC3164Decoder_Decode(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))
}
}

func BenchmarkSyslogRFC3164Decoder_DecodeToJson(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)

root := insaneJSON.Spawn()
defer insaneJSON.Release(root)

for b.Loop() {
_ = d.DecodeToJson(root, []byte(input))
}
}
24 changes: 24 additions & 0 deletions decoder/syslog_rfc5424_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

insaneJSON "github.com/ozontech/insane-json"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -482,3 +483,26 @@ func TestSyslogRFC5424(t *testing.T) {
})
}
}

func BenchmarkSyslogRFC5424_Decode(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))
}
}

func BenchmarkSyslogRFC5424_DecodeToJson(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)

root := insaneJSON.Spawn()
defer insaneJSON.Release(root)

for b.Loop() {
_ = d.DecodeToJson(root, []byte(input))
}
}