From 3d2bd0827fbec6fc4f8f9aeda9030f1a9c4dee61 Mon Sep 17 00:00:00 2001 From: Jacob Bovee Date: Thu, 24 Oct 2024 15:22:43 -0700 Subject: [PATCH] Add initial StringUtils benchmark (#373) --- .gitignore | 5 +++- .../AssemblyInfo.cs | 1 + tests/Benchmarks/Benchmarks.csproj | 23 +++++++++++++++++++ tests/Benchmarks/Program.cs | 5 ++++ tests/Benchmarks/StringUtilsBenchmark.cs | 16 +++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/Benchmarks/Benchmarks.csproj create mode 100644 tests/Benchmarks/Program.cs create mode 100644 tests/Benchmarks/StringUtilsBenchmark.cs diff --git a/.gitignore b/.gitignore index 27a0eab5..8525b1c4 100644 --- a/.gitignore +++ b/.gitignore @@ -255,4 +255,7 @@ paket-files/ global.json # Anything that is local -local.* \ No newline at end of file +local.* + +# BenchmarkDotNet Results +BenchmarkDotNet.Artifacts/ \ No newline at end of file diff --git a/src/ApplicationInsights.Kubernetes/AssemblyInfo.cs b/src/ApplicationInsights.Kubernetes/AssemblyInfo.cs index bb1f6f24..ca1463f6 100644 --- a/src/ApplicationInsights.Kubernetes/AssemblyInfo.cs +++ b/src/ApplicationInsights.Kubernetes/AssemblyInfo.cs @@ -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")] diff --git a/tests/Benchmarks/Benchmarks.csproj b/tests/Benchmarks/Benchmarks.csproj new file mode 100644 index 00000000..4a45fdc4 --- /dev/null +++ b/tests/Benchmarks/Benchmarks.csproj @@ -0,0 +1,23 @@ + + + + + + + + + + + + Exe + net8.0 + enable + enable + + + True + ..\..\src\PublicKey.snk + True + + + diff --git a/tests/Benchmarks/Program.cs b/tests/Benchmarks/Program.cs new file mode 100644 index 00000000..6b60721e --- /dev/null +++ b/tests/Benchmarks/Program.cs @@ -0,0 +1,5 @@ +using Benchmark; +using BenchmarkDotNet.Running; + +var summary = BenchmarkRunner.Run(); +Console.WriteLine(summary); \ No newline at end of file diff --git a/tests/Benchmarks/StringUtilsBenchmark.cs b/tests/Benchmarks/StringUtilsBenchmark.cs new file mode 100644 index 00000000..e765dbd0 --- /dev/null +++ b/tests/Benchmarks/StringUtilsBenchmark.cs @@ -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); + } +}