diff --git a/benchmarks/benchmarks_test.go b/benchmarks/benchmarks_test.go index ca538e06..063963dc 100644 --- a/benchmarks/benchmarks_test.go +++ b/benchmarks/benchmarks_test.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "log" + "math" "testing" "github.com/go-echarts/go-echarts/v2/charts" @@ -215,6 +216,14 @@ func BenchmarkDeserializeNative(b *testing.B) { b.ReportAllocs() } +func nsPerPoint(b *testing.B, dataPointCount int) float64 { + totalDpCount := b.N * dataPointCount + if totalDpCount == 0 { + return 0 + } + return math.Round(float64(b.Elapsed().Nanoseconds()) / float64(totalDpCount)) +} + func BenchmarkSerializeFromPdata(b *testing.B) { chart.BeginChart("Serialization From pdata Speed", b) defer chart.EndChart( @@ -245,7 +254,7 @@ func BenchmarkSerializeFromPdata(b *testing.B) { b, encoding.LongName(), "CPU time to serialize one data point", - float64(b.Elapsed().Nanoseconds())/float64(b.N*batch.DataPointCount()), + nsPerPoint(b, batch.DataPointCount()), ) }, ) @@ -297,7 +306,7 @@ func BenchmarkDeserializeToPdata(b *testing.B) { b, encoding.LongName(), "CPU time to deserialize one data point", - float64(b.Elapsed().Nanoseconds())/float64(b.N*batch.DataPointCount()), + nsPerPoint(b, batch.DataPointCount()), ) }, ) diff --git a/benchmarks/charts.go b/benchmarks/charts.go index c40dd3e2..e06dde43 100644 --- a/benchmarks/charts.go +++ b/benchmarks/charts.go @@ -110,11 +110,16 @@ func (c *BarOutput) EndChart(unit string, globalopts ...charts.GlobalOpts) { require.NoError(c.t, err) } +func roundFloat(val float64, decimals int) float64 { + pow := math.Pow(10, float64(decimals)) + return math.Round(val*pow) / pow +} + func (c *BarOutput) Record(b *testing.B, encoding string, series string, val float64) { if b != nil { b.ReportMetric(val, "ns/point") } - c.results[encoding] = map[string]float64{series: math.Round(val)} + c.results[encoding] = map[string]float64{series: val} } func (c *BarOutput) RecordStacked(b *testing.B, encoding string, series string, val float64) { diff --git a/benchmarks/size_test.go b/benchmarks/size_test.go index 90728c3a..c878527b 100644 --- a/benchmarks/size_test.go +++ b/benchmarks/size_test.go @@ -76,6 +76,13 @@ var sizeEncodings = []encodings.MetricEncoding{ &otelarrow.OtelArrowEncoding{}, } +func unitSize(totalSize int, unitCount int) float64 { + if unitCount == 0 { + return 0 + } + return roundFloat(float64(totalSize)/float64(unitCount), 1) +} + func TestMetricsSize(t *testing.T) { fmt.Println("===== Encoded sizes") @@ -164,15 +171,15 @@ func TestMetricsSize(t *testing.T) { if wantChart { chart.Record( nil, encoding.LongName(), - "Compressed size in bytes (zstd)", - float64(zstdedSize), + "Bytes/point (zstd)", + unitSize(zstdedSize, pointCount), ) } } if wantChart { chart.EndChart( - "Bytes", + "Bytes/point", charts.WithColorsOpts(opts.Colors{"#92C5F9"}), ) } @@ -221,7 +228,9 @@ func TestMetricsMultipart(t *testing.T) { parts, err := testutils.ReadMultipartOTLPFile("testdata/" + dataset.name + ".zst") require.NoError(t, err) + pointCount := 0 for _, part := range parts { + pointCount += part.DataPointCount() err := stream.AppendPart(part) require.NoError(t, err) } @@ -243,13 +252,13 @@ func TestMetricsMultipart(t *testing.T) { } chart.Record( - nil, encoding.LongName(), "Size in bytes, compression="+compression, - float64(curSize), + nil, encoding.LongName(), "Bytes/point, compression="+compression, + unitSize(curSize, pointCount), ) } chart.EndChart( - "Bytes", + "Bytes/point", charts.WithColorsOpts(opts.Colors{"#87BB62"}), ) } @@ -342,6 +351,7 @@ func TestTracesMultipart(t *testing.T) { chart.BeginChart("Dataset: "+fileName, t) otlpSize := 0 + spanCount := 0 for i := 0; i < len(traceData); i++ { if compression == pkg.CompressionNone { otlpSize += len(otlpParts[i]) @@ -349,11 +359,12 @@ func TestTracesMultipart(t *testing.T) { otlpZstd := testutils.CompressZstd(otlpParts[i]) otlpSize += len(otlpZstd) } + spanCount += traceData[i].(ptrace.Traces).SpanCount() } chart.Record( - nil, "OTLP", "Size in bytes, compression="+compressionStr, - float64(otlpSize), + nil, "OTLP", "Bytes/span, compression="+compressionStr, + unitSize(otlpSize, spanCount), ) for _, sorted := range sorteds { @@ -381,19 +392,27 @@ func TestTracesMultipart(t *testing.T) { stefSize := len(outputBuf.Bytes()) - fmt.Printf("Traces OTLP: %8d\n", otlpSize) - fmt.Printf("Traces STEF: %8d\n", stefSize) + fmt.Printf( + "Traces OTLP: %8d (%5.1f bytes/span)\n", + otlpSize, + float64(otlpSize)/float64(spanCount), + ) + fmt.Printf( + "Traces STEF: %8d (%5.1f bytes/span)\n", + stefSize, + float64(stefSize)/float64(spanCount), + ) fmt.Printf( "Ratio: %8.2f\n", float64(otlpSize)/float64(stefSize), ) chart.Record( - nil, "STEF "+sortedStr, "Size in bytes, compression="+compressionStr, - float64(stefSize), + nil, "STEF "+sortedStr, "Bytes/span, compression="+compressionStr, + unitSize(stefSize, spanCount), ) } chart.EndChart( - "Bytes", + "Bytes/span", charts.WithColorsOpts(opts.Colors{"#87BB62"}), ) } diff --git a/docs/benchmarks.html b/docs/benchmarks.html index 424b78d7..55c373ff 100644 --- a/docs/benchmarks.html +++ b/docs/benchmarks.html @@ -9,186 +9,186 @@

Size Benchmarks - One Large Batch

-
+
-
+
-
+

Size - Many Batches, Multipart Metrics

-
+
-
+
-
+
-
+

Size - Many Batches, Multipart Traces

-
+
-
+
-
+
-
+

Speed Benchmarks

-
+
-
+
-
+
-
+
\ No newline at end of file