Skip to content

Commit 456ebbc

Browse files
committed
merge dev into features/native-aot
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
2 parents acc1d0a + a067d91 commit 456ebbc

File tree

86 files changed

+572
-115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+572
-115
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using BenchmarkDotNet.Attributes;
6+
using Light.GuardClauses.FrameworkExtensions;
7+
8+
namespace Light.GuardClauses.Performance.CollectionAssertions;
9+
10+
public class ListCountBenchmark
11+
{
12+
public List<int> List;
13+
14+
// ReSharper disable once UnusedAutoPropertyAccessor.Global
15+
[Params(100, 1000)]
16+
public int NumberOfItems { get; set; }
17+
18+
[GlobalSetup]
19+
public void Setup() => List = Enumerable.Range(1, NumberOfItems).ToList();
20+
21+
// ReSharper disable once UseCollectionCountProperty
22+
[Benchmark(Baseline = true)]
23+
public int LinqCount() => List.Count();
24+
25+
[Benchmark]
26+
public int ExistingEnumerableCount() => EnumerableExtensions.Count(List);
27+
28+
[Benchmark]
29+
public int NewEnumerableOfTGetCount() => List.GetCount();
30+
}
31+
32+
public class StringCountBenchmark
33+
{
34+
public string String;
35+
36+
// ReSharper disable once UnusedAutoPropertyAccessor.Global
37+
[Params(100, 1000)]
38+
public int NumberOfItems { get; set; }
39+
40+
[GlobalSetup]
41+
public void Setup()
42+
{
43+
var random = new Random(42);
44+
var array = new char[NumberOfItems];
45+
for (var i = 0; i < array.Length; i++)
46+
{
47+
array[i] = (char) random.Next('a', 'z' + 1);
48+
}
49+
50+
String = new (array);
51+
}
52+
53+
// ReSharper disable once UseCollectionCountProperty
54+
[Benchmark(Baseline = true)]
55+
public int LinqCount() => String.Count();
56+
57+
[Benchmark]
58+
public int ExistingEnumerableCount() => EnumerableExtensions.Count(String);
59+
60+
[Benchmark]
61+
public int NewEnumerableOfTGetCount() => String.GetCount();
62+
}
63+
64+
public class MyImmutableArrayCountBenchmark
65+
{
66+
public MyImmutableArray<int> MyArray;
67+
68+
// ReSharper disable once UnusedAutoPropertyAccessor.Global
69+
[Params(100, 1000)]
70+
public int NumberOfItems { get; set; }
71+
72+
[GlobalSetup]
73+
public void Setup() => MyArray = new (Enumerable.Range(1, NumberOfItems).ToArray());
74+
75+
// ReSharper disable once UseCollectionCountProperty
76+
[Benchmark(Baseline = true)]
77+
public int LinqCount() => MyArray.Count();
78+
79+
[Benchmark]
80+
public int ExistingEnumerableCount() => EnumerableExtensions.Count(MyArray);
81+
82+
[Benchmark]
83+
public int NewEnumerableOfTGetCount() => MyArray.GetCount();
84+
}
85+
86+
public sealed class MyImmutableArray<T> : IReadOnlyList<T>
87+
{
88+
private readonly T[] _array;
89+
90+
public MyImmutableArray(T[] array) => _array = array;
91+
92+
public IEnumerator<T> GetEnumerator() => ((IEnumerable<T>) _array).GetEnumerator();
93+
94+
IEnumerator IEnumerable.GetEnumerator() => _array.GetEnumerator();
95+
96+
public int Count => _array.Length;
97+
98+
public T this[int index] => _array[index];
99+
}

Code/Light.GuardClauses.Performance/Light.GuardClauses.Performance.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFrameworks>net8.0;net48</TargetFrameworks>
6+
<LangVersion>11</LangVersion>
67
</PropertyGroup>
78

89
<ItemGroup>
910
<ProjectReference Include="..\Light.GuardClauses\Light.GuardClauses.csproj" />
10-
<PackageReference Include="BenchmarkDotNet" Version="0.13.7" />
11+
<PackageReference Include="BenchmarkDotNet" Version="0.13.9" />
1112
</ItemGroup>
1213

1314
</Project>

Code/Light.GuardClauses.Performance/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class Program
1111
private static IConfig DefaultConfiguration =>
1212
DefaultConfig
1313
.Instance
14-
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core60))
14+
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core70))
1515
.AddJob(Job.Default.WithRuntime(ClrRuntime.Net48))
1616
.AddDiagnoser(MemoryDiagnoser.Default, new DisassemblyDiagnoser(new DisassemblyDiagnoserConfig()));
1717

Code/Light.GuardClauses.Tests/CollectionAssertions/MustBeOneOfTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ public static void CallerArgumentExpression()
6969
Action act = () => myNumber.MustBeOneOf(Enumerable.Range(1, 10));
7070

7171
act.Should().Throw<ValueIsNotOneOfException>()
72-
.And.ParamName.Should().Be(nameof(myNumber));
72+
.WithParameterName(nameof(myNumber));
7373
}
7474
}

Code/Light.GuardClauses.Tests/CollectionAssertions/MustContainTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ public static void CallerArgumentExpression()
6767
var act = () => array.MustContain("Baz");
6868

6969
act.Should().Throw<MissingItemException>()
70-
.And.ParamName.Should().Be(nameof(array));
70+
.WithParameterName(nameof(array));
7171
}
7272
}

Code/Light.GuardClauses.Tests/CollectionAssertions/MustHaveCountTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ public static void CallerArgumentExpression()
6868
Action act = () => collection.MustHaveCount(5);
6969

7070
act.Should().Throw<InvalidCollectionCountException>()
71-
.And.ParamName.Should().Be(nameof(collection));
71+
.WithParameterName(nameof(collection));
7272
}
7373
}

Code/Light.GuardClauses.Tests/CollectionAssertions/MustHaveMaximumCountTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ public static void CallerArgumentExpression()
6969
var act = () => myCollection.MustHaveMaximumCount(2);
7070

7171
act.Should().Throw<InvalidCollectionCountException>()
72-
.And.ParamName.Should().Be(nameof(myCollection));
72+
.WithParameterName(nameof(myCollection));
7373
}
7474
}

Code/Light.GuardClauses.Tests/CollectionAssertions/MustHaveMinimumCountTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ public static void CallerArgumentExpression()
7070
Action act = () => myCollection.MustHaveMinimumCount(5);
7171

7272
act.Should().Throw<InvalidCollectionCountException>()
73-
.And.ParamName.Should().Be(nameof(myCollection));
73+
.WithParameterName(nameof(myCollection));
7474
}
7575
}

Code/Light.GuardClauses.Tests/CollectionAssertions/MustNotBeNullOrEmptyTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static void CollectionNull()
1515
Action act = () => ((object[]) null).MustNotBeNullOrEmpty("Foo");
1616

1717
act.Should().Throw<ArgumentNullException>()
18-
.And.ParamName.Should().Be("Foo");
18+
.WithParameterName("Foo");
1919
}
2020

2121
[Fact]
@@ -68,7 +68,7 @@ public static void CallerArgumentExpressionForEmptyCollection()
6868
Action act = () => emptyArray.MustNotBeNullOrEmpty();
6969

7070
act.Should().Throw<EmptyCollectionException>()
71-
.And.ParamName.Should().Be(nameof(emptyArray));
71+
.WithParameterName(nameof(emptyArray));
7272
}
7373

7474
[Fact]
@@ -80,6 +80,6 @@ public static void CallerArgumentExpressionForNull()
8080
Action act = () => nullArray.MustNotBeNullOrEmpty();
8181

8282
act.Should().Throw<ArgumentNullException>()
83-
.And.ParamName.Should().Be(nameof(nullArray));
83+
.WithParameterName(nameof(nullArray));
8484
}
8585
}

Code/Light.GuardClauses.Tests/CollectionAssertions/MustNotBeOneOfTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ public static void CallerArgumentExpression()
6767
Action act = () => fortyTwo.MustNotBeOneOf(new[] { 42 });
6868

6969
act.Should().Throw<ValueIsOneOfException>()
70-
.And.ParamName.Should().Be(nameof(fortyTwo));
70+
.WithParameterName(nameof(fortyTwo));
7171
}
7272
}

0 commit comments

Comments
 (0)