Skip to content

Commit

Permalink
Tweaks to ActivityCreation benchmarks (#5173)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Dec 14, 2023
1 parent 1477c85 commit 2bccad8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
25 changes: 13 additions & 12 deletions test/Benchmarks/Helper/ActivityCreationScenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,31 @@ public static void CreateActivity(ActivitySource source)
activity?.Stop();
}

public static void CreateActivityWithKind(ActivitySource source)
{
using var activity = source.StartActivity("name", ActivityKind.Client);
activity?.Stop();
}

public static void CreateActivityFromParentContext(ActivitySource source, ActivityContext parentCtx)
{
using var activity = source.StartActivity("name", ActivityKind.Internal, parentCtx);
activity?.Stop();
}

public static void CreateActivityFromParentId(ActivitySource source, string parentId)
public static void CreateActivityWithSetTags(ActivitySource source)
{
using var activity = source.StartActivity("name", ActivityKind.Internal, parentId);
using var activity = source.StartActivity("name");
activity?.SetTag("tag1", "string");
activity?.SetTag("tag2", 1);
activity?.SetTag("tag3", true);
activity?.SetTag("tag4", "string-again");
activity?.SetTag("tag5", "string-more");
activity?.Stop();
}

public static void CreateActivityWithAttributes(ActivitySource source)
public static void CreateActivityWithAddTags(ActivitySource source)
{
using var activity = source.StartActivity("name");
activity?.SetTag("tag1", "string");
activity?.SetTag("tag2", 1);
activity?.SetTag("tag3", true);
activity?.AddTag("tag1", "string");
activity?.AddTag("tag2", 1);
activity?.AddTag("tag3", true);
activity?.AddTag("tag4", "string-again");
activity?.AddTag("tag5", "string-more");
activity?.Stop();
}
}
28 changes: 14 additions & 14 deletions test/Benchmarks/Trace/ActivityCreationBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@
using OpenTelemetry.Trace;

/*
BenchmarkDotNet v0.13.10, Windows 11 (10.0.23424.1000)
Intel Core i7-9700 CPU 3.00GHz, 1 CPU, 8 logical and 8 physical cores
BenchmarkDotNet v0.13.10, Windows 11 (10.0.22621.2861)
11th Gen Intel Core i7-1185G7 3.00GHz, 1 CPU, 8 logical and 4 physical cores
.NET SDK 8.0.100
[Host] : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2
DefaultJob : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|----------------------------------------------- |----------:|---------:|---------:|-------:|----------:|
| CreateActivity_NoopProcessor | 307.12 ns | 5.769 ns | 6.172 ns | 0.0663 | 416 B |
| CreateActivity_WithParentContext_NoopProcessor | 75.18 ns | 0.399 ns | 0.354 ns | - | - |
| CreateActivity_WithParentId_NoopProcessor | 156.52 ns | 1.609 ns | 1.426 ns | 0.0229 | 144 B |
| CreateActivity_WithAttributes_NoopProcessor | 372.34 ns | 6.215 ns | 4.852 ns | 0.0992 | 624 B |
| CreateActivity_WithKind_NoopProcessor | 302.24 ns | 5.859 ns | 8.402 ns | 0.0663 | 416 B |
| Method | Mean | Error | StdDev | Median |
|----------------------------------------------- |----------:|---------:|----------:|----------:|
| CreateActivity_NoopProcessor | 247.22 ns | 4.977 ns | 13.198 ns | 240.34 ns |
| CreateActivity_WithParentContext_NoopProcessor | 55.17 ns | 1.131 ns | 1.111 ns | 54.98 ns |
| CreateActivity_WithSetTags_NoopProcessor | 375.2 ns | 7.52 ns | 18.44 ns | 370.4 ns |
| CreateActivity_WithAddTags_NoopProcessor | 340.9 ns | 6.27 ns | 12.81 ns | 336.1 ns |
*/

namespace Benchmarks.Trace;
Expand All @@ -30,14 +29,14 @@ public class ActivityCreationBenchmarks
{
private readonly ActivitySource benchmarkSource = new("Benchmark");
private readonly ActivityContext parentCtx = new(ActivityTraceId.CreateRandom(), ActivitySpanId.CreateRandom(), ActivityTraceFlags.None);
private readonly string parentId = $"00-{ActivityTraceId.CreateRandom()}.{ActivitySpanId.CreateRandom()}.00";
private TracerProvider tracerProvider;

[GlobalSetup]
public void GlobalSetup()
{
this.tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("BenchMark")
.AddProcessor(new NoopActivityProcessor())
.Build();
}

Expand All @@ -55,11 +54,12 @@ public void GlobalCleanup()
public void CreateActivity_WithParentContext_NoopProcessor() => ActivityCreationScenarios.CreateActivityFromParentContext(this.benchmarkSource, this.parentCtx);

[Benchmark]
public void CreateActivity_WithParentId_NoopProcessor() => ActivityCreationScenarios.CreateActivityFromParentId(this.benchmarkSource, this.parentId);
public void CreateActivity_WithSetTags_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithSetTags(this.benchmarkSource);

[Benchmark]
public void CreateActivity_WithAttributes_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAttributes(this.benchmarkSource);
public void CreateActivity_WithAddTags_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithAddTags(this.benchmarkSource);

[Benchmark]
public void CreateActivity_WithKind_NoopProcessor() => ActivityCreationScenarios.CreateActivityWithKind(this.benchmarkSource);
internal class NoopActivityProcessor : BaseProcessor<Activity>
{
}
}

0 comments on commit 2bccad8

Please sign in to comment.