Skip to content

Commit

Permalink
test(bench): add OTEL validate
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Jan 16, 2022
1 parent 3eba1d5 commit ed2c257
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
14 changes: 13 additions & 1 deletion otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down

0 comments on commit ed2c257

Please sign in to comment.