-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from linksplatform/feature/benchmarks/add_lamb…
…da_vs_setter_benchmarks Add `LambdaVsSetterBenchmarks`
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
csharp/Platform.Setters.Benchmarks/LambdaVsSetterBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IList<int>, int> func) => func(new List<int> { 0, 1, 2, 3 }); | ||
|
||
[Benchmark] | ||
public int LambdaBenchmark() | ||
{ | ||
int result; | ||
var trueValue = 1; | ||
var falseValue = 2; | ||
int Lambda(IList<int> list) | ||
{ | ||
result = list[0]; | ||
return trueValue; | ||
} | ||
return Process(Lambda); | ||
} | ||
|
||
[Benchmark] | ||
public int SetterBenchmark() | ||
{ | ||
var setter = new Setter<int, int>(1, 2); | ||
return Process(setter.SetFirstAndReturnTrue); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
csharp/Platform.Setters.Benchmarks/Platform.Setters.Benchmarks.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFrameworks>net472;netstandard2.0;netstandard2.1;net5</TargetFrameworks> | ||
<IsPackable>false</IsPackable> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Platform.Setters\Platform.Setters.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using BenchmarkDotNet.Running; | ||
|
||
namespace Platform.Setters.Benchmarks | ||
{ | ||
class Program | ||
{ | ||
static void Main() | ||
{ | ||
BenchmarkRunner.Run<LambdaVsSetterBenchmarks>(); | ||
} | ||
} | ||
} |