Skip to content

Commit

Permalink
Benchmark for all versions of proto
Browse files Browse the repository at this point in the history
  • Loading branch information
victlu committed Apr 24, 2021
1 parent 8aaaf9a commit a8824f4
Show file tree
Hide file tree
Showing 80 changed files with 6,034 additions and 272 deletions.
282 changes: 157 additions & 125 deletions test/Benchmarks-Proto/Benchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.
// </copyright>

using System.Collections.Generic;
using BenchmarkDotNet.Attributes;

/*
Expand Down Expand Up @@ -58,16 +59,12 @@ public class Benchmarks
{
private (string name, object value)[] resources;
private (string name, string value)[] labels;
private byte[] oldIntBytes;
private byte[] newIntBytes;
private byte[] oldDoubleBytes;
private byte[] newDoubleBytes;
private byte[] oldIntBatchBytes;
private byte[] newIntBatchBytes;
private byte[] oldSummaryBytes;
private byte[] newSummaryBytes;
private byte[] oldHistogramBytes;
private byte[] newHistogramBytes;
private byte[] bytesGauge;
private byte[] bytesSummary;
private byte[] bytesHistogram;

[Params("0.4.0", "0.5.0", "0.6.0", "0.7.0", "0.8.0")]
public string Version { get; set; }

[GlobalSetup]
public void Setup()
Expand All @@ -86,160 +83,195 @@ public void Setup()
("label2", "val2"),
};

this.newIntBytes = ProtoNew.Encode(false, this.resources, this.labels, 1, 100, 1);
this.oldIntBytes = ProtoOld.Encode(false, this.resources, this.labels, 1, 100, 1);
this.bytesGauge = this.EncodeGauge();
this.bytesSummary = this.EncodeSummary();
this.bytesHistogram = this.EncodeHistogram();
}

this.newDoubleBytes = ProtoNew.Encode(true, this.resources, this.labels, 1, 100, 1);
this.oldDoubleBytes = ProtoOld.Encode(true, this.resources, this.labels, 1, 100, 1);
[Benchmark]
public byte[] EncodeGauge()
{
byte[] bytes = new byte[0];

this.newIntBatchBytes = ProtoNew.Encode(false, this.resources, this.labels, 1, 100, 5);
this.oldIntBatchBytes = ProtoOld.Encode(false, this.resources, this.labels, 1, 100, 5);
switch (this.Version)
{
case "0.4.0":
bytes = Otlp040.EncodeGauge(false, this.resources, this.labels, 1, 100, 1);
break;

this.newSummaryBytes = ProtoNew.EncodeSummary(this.resources, this.labels, 1, 100, 1, 10);
this.oldSummaryBytes = ProtoOld.EncodeSummary(this.resources, this.labels, 1, 100, 1, 10);
case "0.5.0":
bytes = Otlp050.EncodeGauge(false, this.resources, this.labels, 1, 100, 1);
break;

this.newHistogramBytes = ProtoNew.EncodeHistogram(this.resources, this.labels, 1, 100, 1, 2, 2);
this.oldHistogramBytes = ProtoOld.EncodeHistogram(this.resources, this.labels, 1, 100, 1, 2, 2);
}
case "0.6.0":
bytes = Otlp060.EncodeGauge(false, this.resources, this.labels, 1, 100, 1);
break;

[Benchmark]
public int EncodeIntNew()
{
var bytes = ProtoNew.Encode(false, this.resources, this.labels, 1, 100, 1);
return bytes.Length;
}
case "0.7.0":
bytes = Otlp070.EncodeGauge(false, this.resources, this.labels, 1, 100, 1);
break;

[Benchmark]
public int EncodeIntOld()
{
var bytes = ProtoOld.Encode(false, this.resources, this.labels, 1, 100, 1);
return bytes.Length;
}
case "0.8.0":
bytes = Otlp080.EncodeGauge(false, this.resources, this.labels, 1, 100, 1);
break;
}

[Benchmark]
public int DecodeIntNew()
{
var extracts = ProtoNew.Decode(this.newIntBytes);
return extracts.Count;
return bytes;
}

[Benchmark]
public int DecodeIntOld()
public List<string> DecodeGauge()
{
var extracts = ProtoOld.Decode(this.oldIntBytes);
return extracts.Count;
}
List<string> extracts = new List<string>();

[Benchmark]
public int EncodeIntBatchNew()
{
var bytes = ProtoNew.Encode(false, this.resources, this.labels, 1, 100, 5);
return bytes.Length;
}
switch (this.Version)
{
case "0.4.0":
extracts = Otlp040.Decode(this.bytesGauge);
break;

[Benchmark]
public int EncodeIntBatchOld()
{
var bytes = ProtoOld.Encode(false, this.resources, this.labels, 1, 100, 5);
return bytes.Length;
}
case "0.5.0":
extracts = Otlp050.Decode(this.bytesGauge);
break;

[Benchmark]
public int DecodeIntBatchNew()
{
var extracts = ProtoNew.Decode(this.newIntBatchBytes);
return extracts.Count;
}
case "0.6.0":
extracts = Otlp060.Decode(this.bytesGauge);
break;

[Benchmark]
public int DecodeIntBatchOld()
{
var extracts = ProtoOld.Decode(this.oldIntBatchBytes);
return extracts.Count;
}
case "0.7.0":
extracts = Otlp070.Decode(this.bytesGauge);
break;

[Benchmark]
public int EncodeDoubleNew()
{
var bytes = ProtoNew.Encode(true, this.resources, this.labels, 1, 100, 1);
return bytes.Length;
}
case "0.8.0":
extracts = Otlp080.Decode(this.bytesGauge);
break;
}

[Benchmark]
public int EncodeDoubleOld()
{
var bytes = ProtoOld.Encode(true, this.resources, this.labels, 1, 100, 1);
return bytes.Length;
return extracts;
}

[Benchmark]
public int DecodeDoubleNew()
public byte[] EncodeSummary()
{
var extracts = ProtoNew.Decode(this.newDoubleBytes);
return extracts.Count;
}
byte[] bytes = new byte[0];

[Benchmark]
public int DecodeDoubleOld()
{
var extracts = ProtoOld.Decode(this.oldDoubleBytes);
return extracts.Count;
}
switch (this.Version)
{
case "0.4.0":
bytes = Otlp040.EncodeSummary(this.resources, this.labels, 1, 100, 1, 4);
break;

[Benchmark]
public int EncodeSummaryNew()
{
var bytes = ProtoNew.EncodeSummary(this.resources, this.labels, 1, 100, 1, 10);
return bytes.Length;
}
case "0.5.0":
bytes = Otlp050.EncodeSummary(this.resources, this.labels, 1, 100, 1, 4);
break;

[Benchmark]
public int EncodeSummaryOld()
{
var bytes = ProtoOld.EncodeSummary(this.resources, this.labels, 1, 100, 1, 10);
return bytes.Length;
}
case "0.7.0":
bytes = Otlp070.EncodeSummary(this.resources, this.labels, 1, 100, 1, 4);
break;

[Benchmark]
public int DecodeSummaryNew()
{
var extracts = ProtoNew.Decode(this.newSummaryBytes);
return extracts.Count;
}
case "0.6.0":
bytes = Otlp060.EncodeSummary(this.resources, this.labels, 1, 100, 1, 4);
break;

[Benchmark]
public int DecodeSummaryOld()
{
var extracts = ProtoOld.Decode(this.oldSummaryBytes);
return extracts.Count;
}
case "0.8.0":
bytes = Otlp080.EncodeSummary(this.resources, this.labels, 1, 100, 1, 4);
break;
}

[Benchmark]
public int EncodeHistogramNew()
{
var bytes = ProtoNew.EncodeHistogram(this.resources, this.labels, 1, 100, 1, 2, 2);
return bytes.Length;
return bytes;
}

[Benchmark]
public int EncodeHistogramOld()
public List<string> DecodeSummary()
{
var bytes = ProtoOld.EncodeHistogram(this.resources, this.labels, 1, 100, 1, 2, 2);
return bytes.Length;
List<string> extracts = new List<string>();

switch (this.Version)
{
case "0.4.0":
extracts = Otlp040.Decode(this.bytesSummary);
break;

case "0.5.0":
extracts = Otlp050.Decode(this.bytesSummary);
break;

case "0.6.0":
extracts = Otlp060.Decode(this.bytesSummary);
break;

case "0.7.0":
extracts = Otlp070.Decode(this.bytesSummary);
break;

case "0.8.0":
extracts = Otlp080.Decode(this.bytesSummary);
break;
}

return extracts;
}

[Benchmark]
public int DecodeHistogramNew()
public byte[] EncodeHistogram()
{
var extracts = ProtoNew.Decode(this.newHistogramBytes);
return extracts.Count;
byte[] bytes = new byte[0];

switch (this.Version)
{
case "0.4.0":
bytes = Otlp040.EncodeHistogram(this.resources, this.labels, 1, 100, 1, 4, 1);
break;

case "0.5.0":
bytes = Otlp050.EncodeHistogram(this.resources, this.labels, 1, 100, 1, 4, 1);
break;

case "0.7.0":
bytes = Otlp070.EncodeHistogram(this.resources, this.labels, 1, 100, 1, 4, 1);
break;

case "0.6.0":
bytes = Otlp060.EncodeHistogram(this.resources, this.labels, 1, 100, 1, 4, 1);
break;

case "0.8.0":
bytes = Otlp080.EncodeHistogram(this.resources, this.labels, 1, 100, 1, 4, 1);
break;
}

return bytes;
}

[Benchmark]
public int DecodeHistogramOld()
public List<string> DecodeHistogram()
{
var extracts = ProtoOld.Decode(this.oldHistogramBytes);
return extracts.Count;
List<string> extracts = new List<string>();

switch (this.Version)
{
case "0.4.0":
extracts = Otlp040.Decode(this.bytesHistogram);
break;

case "0.5.0":
extracts = Otlp050.Decode(this.bytesHistogram);
break;

case "0.7.0":
extracts = Otlp070.Decode(this.bytesHistogram);
break;

case "0.6.0":
extracts = Otlp060.Decode(this.bytesHistogram);
break;

case "0.8.0":
extracts = Otlp080.Decode(this.bytesHistogram);
break;
}

return extracts;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="ProtoOld.cs" company="OpenTelemetry Authors">
// <copyright file="Otlp040.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,15 +19,16 @@
using System.Linq;
using Google.Protobuf;
using Google.Protobuf.Collections;
using Opentelemetry4.Proto.Collector.Metrics.V1;
using Opentelemetry4.Proto.Common.V1;
using Opentelemetry4.Proto.Metrics.V1;
using Opentelemetry040.Proto.Collector.Metrics.V1;
using Opentelemetry040.Proto.Common.V1;
using Opentelemetry040.Proto.Metrics.V1;
using Opentelemetry040.Proto.Resource.V1;

namespace ProtoBench
{
public class ProtoOld
public class Otlp040
{
public static byte[] Encode(
public static byte[] EncodeGauge(
bool isDouble,
(string name, object value)[] resources,
(string name, string value)[] labels,
Expand Down Expand Up @@ -98,7 +99,7 @@ public static byte[] Encode(
resmetric.InstrumentationLibraryMetrics.Add(instMetric);
}

resmetric.Resource = new Opentelemetry4.Proto.Resource.V1.Resource();
resmetric.Resource = new Resource();
resmetric.Resource.DroppedAttributesCount = 0;
var attribs = resmetric.Resource.Attributes;
foreach (var resource in resources)
Expand Down Expand Up @@ -187,7 +188,7 @@ public static byte[] EncodeSummary(
resmetric.InstrumentationLibraryMetrics.Add(instMetric);
}

resmetric.Resource = new Opentelemetry4.Proto.Resource.V1.Resource();
resmetric.Resource = new Resource();
resmetric.Resource.DroppedAttributesCount = 0;
var attribs = resmetric.Resource.Attributes;
foreach (var resource in resources)
Expand Down Expand Up @@ -284,7 +285,7 @@ public static byte[] EncodeHistogram(
resmetric.InstrumentationLibraryMetrics.Add(instMetric);
}

resmetric.Resource = new Opentelemetry4.Proto.Resource.V1.Resource();
resmetric.Resource = new Resource();
resmetric.Resource.DroppedAttributesCount = 0;
var attribs = resmetric.Resource.Attributes;
foreach (var resource in resources)
Expand Down
Loading

0 comments on commit a8824f4

Please sign in to comment.