-
Notifications
You must be signed in to change notification settings - Fork 6
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
Showing
11 changed files
with
403 additions
and
395 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
57 changes: 29 additions & 28 deletions
57
NetFabric.Hyperlinq.Analyzer.Benchmarks/HLQ001_AssignmentBoxing.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,37 +1,38 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace NetFabric.Hyperlinq.Analyzer.Benchmarks; | ||
|
||
public class HLQ001_AssignmentBoxing | ||
namespace NetFabric.Hyperlinq.Analyzer.Benchmarks | ||
{ | ||
List<int>? list; | ||
IEnumerable<int>? enumerable; | ||
public class HLQ001_AssignmentBoxing | ||
{ | ||
List<int>? list; | ||
IEnumerable<int>? enumerable; | ||
|
||
[Params(100, 10_000)] | ||
public int Count { get; set; } | ||
[Params(100, 10_000)] | ||
public int Count { get; set; } | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
list = System.Linq.Enumerable.Range(0, Count).ToList(); | ||
enumerable = list; | ||
} | ||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
list = System.Linq.Enumerable.Range(0, Count).ToList(); | ||
enumerable = list; | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public int Enumerable() | ||
{ | ||
var sum = 0; | ||
foreach (var item in enumerable!) | ||
sum += item; | ||
return sum; | ||
} | ||
[Benchmark(Baseline = true)] | ||
public int Enumerable() | ||
{ | ||
var sum = 0; | ||
foreach (var item in enumerable!) | ||
sum += item; | ||
return sum; | ||
} | ||
|
||
[Benchmark] | ||
public int List() | ||
{ | ||
var sum = 0; | ||
foreach (var item in list!) | ||
sum += item; | ||
return sum; | ||
[Benchmark] | ||
public int List() | ||
{ | ||
var sum = 0; | ||
foreach (var item in list!) | ||
sum += item; | ||
return sum; | ||
} | ||
} | ||
} |
63 changes: 32 additions & 31 deletions
63
NetFabric.Hyperlinq.Analyzer.Benchmarks/HLQ004_RefEnumerationVariable.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,45 +1,46 @@ | ||
using BenchmarkDotNet.Attributes; | ||
|
||
namespace NetFabric.Hyperlinq.Analyzer.Benchmarks; | ||
|
||
public class HLQ004_RefEnumerationVariable | ||
namespace NetFabric.Hyperlinq.Analyzer.Benchmarks | ||
{ | ||
public readonly record struct Person(string Name, int Age); | ||
public class HLQ004_RefEnumerationVariable | ||
{ | ||
public readonly record struct Person(string Name, int Age); | ||
|
||
Person[]? people; | ||
Person[]? people; | ||
|
||
[Params(100, 10_000)] | ||
public int Count { get; set; } | ||
[Params(100, 10_000)] | ||
public int Count { get; set; } | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
people = Enumerable.Range(0, Count) | ||
.Select(value => new Person(value.ToString(), value)) | ||
.ToArray(); | ||
} | ||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
people = Enumerable.Range(0, Count) | ||
.Select(value => new Person(value.ToString(), value)) | ||
.ToArray(); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public Person? Copy() | ||
{ | ||
var oldest = default(Person); | ||
foreach (var person in people!.AsSpan()) | ||
[Benchmark(Baseline = true)] | ||
public Person? Copy() | ||
{ | ||
if (person.Age > oldest.Age) | ||
oldest = person; | ||
var oldest = default(Person); | ||
foreach (var person in people!.AsSpan()) | ||
{ | ||
if (person.Age > oldest.Age) | ||
oldest = person; | ||
} | ||
return oldest; | ||
} | ||
return oldest; | ||
} | ||
|
||
[Benchmark] | ||
public Person Ref() | ||
{ | ||
var oldest = default(Person); | ||
foreach (ref var person in people!.AsSpan()) | ||
[Benchmark] | ||
public Person Ref() | ||
{ | ||
if (person.Age > oldest.Age) | ||
oldest = person; | ||
var oldest = default(Person); | ||
foreach (ref var person in people!.AsSpan()) | ||
{ | ||
if (person.Age > oldest.Age) | ||
oldest = person; | ||
} | ||
return oldest; | ||
} | ||
return oldest; | ||
} | ||
} |
77 changes: 39 additions & 38 deletions
77
NetFabric.Hyperlinq.Analyzer.Benchmarks/HLQ005_AvoidSingleAnalyzer.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,45 +1,46 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Configs; | ||
|
||
namespace NetFabric.Hyperlinq.Analyzer.Benchmarks; | ||
|
||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] | ||
[CategoriesColumn] | ||
public class HLQ005_AvoidSingleAnalyzer | ||
namespace NetFabric.Hyperlinq.Analyzer.Benchmarks | ||
{ | ||
int[]? bestCase; | ||
int[]? worstCase; | ||
|
||
[Params(100, 10_000)] | ||
public int Count { get; set; } | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)] | ||
[CategoriesColumn] | ||
public class HLQ005_AvoidSingleAnalyzer | ||
{ | ||
bestCase = Enumerable.Range(0, Count).ToArray(); | ||
worstCase = bestCase.Reverse().ToArray(); | ||
int[]? bestCase; | ||
int[]? worstCase; | ||
|
||
[Params(100, 10_000)] | ||
public int Count { get; set; } | ||
|
||
[GlobalSetup] | ||
public void GlobalSetup() | ||
{ | ||
bestCase = Enumerable.Range(0, Count).ToArray(); | ||
worstCase = bestCase.Reverse().ToArray(); | ||
} | ||
|
||
[BenchmarkCategory("BestCase")] | ||
[Benchmark(Baseline = true)] | ||
public int BestCase_Single() | ||
=> bestCase!.Single(Comparer); | ||
|
||
[BenchmarkCategory("BestCase")] | ||
[Benchmark] | ||
public int BestCase_First() | ||
=> bestCase!.First(Comparer); | ||
|
||
[BenchmarkCategory("WorstCase")] | ||
[Benchmark(Baseline = true)] | ||
public int WorstCase_Single() | ||
=> worstCase!.Single(Comparer); | ||
|
||
[BenchmarkCategory("WorstCase")] | ||
[Benchmark] | ||
public int WorstCase_First() | ||
=> worstCase!.First(Comparer); | ||
|
||
static bool Comparer(int value) | ||
=> value == 0; | ||
} | ||
|
||
[BenchmarkCategory("BestCase")] | ||
[Benchmark(Baseline = true)] | ||
public int BestCase_Single() | ||
=> bestCase!.Single(Comparer); | ||
|
||
[BenchmarkCategory("BestCase")] | ||
[Benchmark] | ||
public int BestCase_First() | ||
=> bestCase!.First(Comparer); | ||
|
||
[BenchmarkCategory("WorstCase")] | ||
[Benchmark(Baseline = true)] | ||
public int WorstCase_Single() | ||
=> worstCase!.Single(Comparer); | ||
|
||
[BenchmarkCategory("WorstCase")] | ||
[Benchmark] | ||
public int WorstCase_First() | ||
=> worstCase!.First(Comparer); | ||
|
||
static bool Comparer(int value) | ||
=> value == 0; | ||
} |
Oops, something went wrong.