From ed2c257a3a3e492fbb2615366d4ae4e32e967da6 Mon Sep 17 00:00:00 2001 From: Aleksandr Razumov Date: Sun, 16 Jan 2022 18:18:00 +0300 Subject: [PATCH] test(bench): add OTEL validate --- README.md | 11 ++++++----- otel_test.go | 14 +++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 90cf0e8..ec3f030 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,12 @@ For example, we have following OpenTelemetry log entry: Flexibility of `jx` enables highly efficient semantic-aware encoding and decoding, e.g. using `[16]byte` for `TraceId` with zero-allocation `hex` encoding in json: -| Name | Speed | Allocations | -|--------|-----------|-------------| -| Decode | 970 MB/s | 0 allocs/op | -| Encode | 1104 MB/s | 0 allocs/op | -| Write | 1800 MB/s | 0 allocs/op | +| Name | Speed | Allocations | +|----------|-----------|-------------| +| Decode | 970 MB/s | 0 allocs/op | +| Validate | 1535 MB/s | 0 allocs/op | +| Encode | 1104 MB/s | 0 allocs/op | +| Write | 1800 MB/s | 0 allocs/op | See [otel_test.go](./otel_test.go) for example. diff --git a/otel_test.go b/otel_test.go index 4423567..300b879 100644 --- a/otel_test.go +++ b/otel_test.go @@ -295,7 +295,7 @@ func TestOTELDecode(t *testing.T) { }) } -func BenchmarkOTEL_Decode(b *testing.B) { +func BenchmarkOTEL(b *testing.B) { var v OTEL dec := DecodeBytes(otelEx1) require.NoError(b, v.Decode(dec)) @@ -314,6 +314,18 @@ func BenchmarkOTEL_Decode(b *testing.B) { } } }) + b.Run("Validate", func(b *testing.B) { + d := GetDecoder() + b.ReportAllocs() + b.SetBytes(int64(len(otelEx1))) + + for i := 0; i < b.N; i++ { + d.ResetBytes(otelEx1) + if d.Validate() != nil { + b.Fatal("invalid") + } + } + }) b.Run("Write", func(b *testing.B) { b.ReportAllocs() var w Writer