diff --git a/Platform.Setters.sln b/Platform.Setters.sln index cbe0cb5..1d345ab 100644 --- a/Platform.Setters.sln +++ b/Platform.Setters.sln @@ -12,6 +12,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Platform.Setters.Tests", "c EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CSharpToCppTranslator", "CSharpToCppTranslator\CSharpToCppTranslator.csproj", "{1394B2AC-0B80-4F29-82C3-A610C3BD6BDB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Platform.Setters.Benchmarks", "csharp\Platform.Setters.Benchmarks\Platform.Setters.Benchmarks.csproj", "{3B7CF42F-46F9-480E-B50D-1AA9A9F02E29}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -30,6 +32,10 @@ Global {1394B2AC-0B80-4F29-82C3-A610C3BD6BDB}.Debug|Any CPU.Build.0 = Debug|Any CPU {1394B2AC-0B80-4F29-82C3-A610C3BD6BDB}.Release|Any CPU.ActiveCfg = Release|Any CPU {1394B2AC-0B80-4F29-82C3-A610C3BD6BDB}.Release|Any CPU.Build.0 = Release|Any CPU + {3B7CF42F-46F9-480E-B50D-1AA9A9F02E29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3B7CF42F-46F9-480E-B50D-1AA9A9F02E29}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3B7CF42F-46F9-480E-B50D-1AA9A9F02E29}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3B7CF42F-46F9-480E-B50D-1AA9A9F02E29}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/csharp/Platform.Setters.Benchmarks/LambdaVsSetterBenchmarks.cs b/csharp/Platform.Setters.Benchmarks/LambdaVsSetterBenchmarks.cs new file mode 100644 index 0000000..2eccce8 --- /dev/null +++ b/csharp/Platform.Setters.Benchmarks/LambdaVsSetterBenchmarks.cs @@ -0,0 +1,33 @@ +using BenchmarkDotNet.Attributes; +using System; +using System.Collections.Generic; + +namespace Platform.Setters.Benchmarks; + +[SimpleJob] +[MemoryDiagnoser] +public class LambdaVsSetterBenchmarks +{ + private int Process(Func, int> func) => func(new List { 0, 1, 2, 3 }); + + [Benchmark] + public int LambdaBenchmark() + { + int result; + var trueValue = 1; + var falseValue = 2; + int Lambda(IList list) + { + result = list[0]; + return trueValue; + } + return Process(Lambda); + } + + [Benchmark] + public int SetterBenchmark() + { + var setter = new Setter(1, 2); + return Process(setter.SetFirstAndReturnTrue); + } +} diff --git a/csharp/Platform.Setters.Benchmarks/Platform.Setters.Benchmarks.csproj b/csharp/Platform.Setters.Benchmarks/Platform.Setters.Benchmarks.csproj new file mode 100644 index 0000000..0415083 --- /dev/null +++ b/csharp/Platform.Setters.Benchmarks/Platform.Setters.Benchmarks.csproj @@ -0,0 +1,19 @@ + + + + Exe + net472;netstandard2.0;netstandard2.1;net5 + false + true + latest + + + + + + + + + + + diff --git a/csharp/Platform.Setters.Benchmarks/Program.cs b/csharp/Platform.Setters.Benchmarks/Program.cs new file mode 100644 index 0000000..d7b3694 --- /dev/null +++ b/csharp/Platform.Setters.Benchmarks/Program.cs @@ -0,0 +1,12 @@ +using BenchmarkDotNet.Running; + +namespace Platform.Setters.Benchmarks +{ + class Program + { + static void Main() + { + BenchmarkRunner.Run(); + } + } +}