Skip to content

Commit

Permalink
Add initial StringUtils benchmark (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBovee authored Oct 24, 2024
1 parent 81610ab commit 3d2bd08
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,7 @@ paket-files/
global.json

# Anything that is local
local.*
local.*

# BenchmarkDotNet Results
BenchmarkDotNet.Artifacts/
1 change: 1 addition & 0 deletions src/ApplicationInsights.Kubernetes/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

// Allow unit tests to access internal members
[assembly: InternalsVisibleTo("Microsoft.ApplicationInsights.Kubernetes.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("Benchmarks, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
23 changes: 23 additions & 0 deletions tests/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\src\ApplicationInsights.Kubernetes\ApplicationInsights.Kubernetes.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchMarkDotNet" Version="0.14.0" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>


<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\src\PublicKey.snk</AssemblyOriginatorKeyFile>
<DelaySign>True</DelaySign>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions tests/Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using Benchmark;
using BenchmarkDotNet.Running;

var summary = BenchmarkRunner.Run<StringUtilsBenchmark>();
Console.WriteLine(summary);
16 changes: 16 additions & 0 deletions tests/Benchmarks/StringUtilsBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using BenchmarkDotNet.Attributes;
using Microsoft.ApplicationInsights.Kubernetes;

namespace Benchmark;

public class StringUtilsBenchmark
{
[Params(25, 1023, 1024, 1025, 2097152, 3758096384, 3848290697216)]
public long Input { get; set; }

[Benchmark]
public string BenchmarkGetReadableSize()
{
return StringUtils.GetReadableSize(Input);
}
}

0 comments on commit 3d2bd08

Please sign in to comment.