Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 11 additions & 2 deletions benchmarks/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
"math"
"testing"

"github.com/go-echarts/go-echarts/v2/charts"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()),
)
},
)
Expand Down Expand Up @@ -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()),
)
},
)
Expand Down
7 changes: 6 additions & 1 deletion benchmarks/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
45 changes: 32 additions & 13 deletions benchmarks/size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"}),
)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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"}),
)
}
Expand Down Expand Up @@ -342,18 +351,20 @@ 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])
} else {
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 {
Expand Down Expand Up @@ -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"}),
)
}
Expand Down
Loading
Loading