-
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.
- Loading branch information
1 parent
64b4b66
commit 0784050
Showing
1 changed file
with
23 additions
and
43 deletions.
There are no files selected for viewing
66 changes: 23 additions & 43 deletions
66
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 |
---|---|---|
@@ -1,53 +1,33 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using BenchmarkDotNet.Attributes; | ||
namespace Platform.Setters.Benchmarks | ||
{ | ||
[SimpleJob] | ||
[MemoryDiagnoser] | ||
public class LambdaVsSetterBenchmarks | ||
{ | ||
[GlobalSetup] | ||
public static void Setup() | ||
{ | ||
|
||
} | ||
namespace Platform.Setters.Benchmarks; | ||
|
||
[GlobalCleanup] | ||
public static void Cleanup() | ||
{ | ||
|
||
} | ||
|
||
int Process(Func<IList<int>, int> func) | ||
{ | ||
return func(new List<int>{0,1,2,3,4,5,6,7,8,9}); | ||
} | ||
|
||
[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); | ||
} | ||
[SimpleJob] | ||
[MemoryDiagnoser] | ||
public class LambdaVsSetterBenchmarks | ||
{ | ||
private int Process(Func<IList<int>, int> func) => func(new List<int> { 0, 1, 2, 3 }); | ||
|
||
[Benchmark] | ||
public int SetterBenchmark() | ||
[Benchmark] | ||
public int LambdaBenchmark() | ||
{ | ||
int result; | ||
var trueValue = 1; | ||
var falseValue = 2; | ||
int Lambda(IList<int> list) | ||
{ | ||
var setter = new Setter<int, int>(1, 2); | ||
return Process(setter.SetFirstAndReturnTrue); | ||
result = list[0]; | ||
return trueValue; | ||
} | ||
|
||
return Process(Lambda); | ||
} | ||
|
||
[Benchmark] | ||
public int SetterBenchmark() | ||
{ | ||
var setter = new Setter<int, int>(1, 2); | ||
return Process(setter.SetFirstAndReturnTrue); | ||
} | ||
} | ||
|