Skip to content

Commit dbffb0a

Browse files
committed
Added Benchmark Dotnet 8
1 parent f5b1113 commit dbffb0a

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<LangVersion>preview</LangVersion>
8+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
9+
<TargetFrameworks>net8.0;net7.0</TargetFrameworks>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="BenchmarkDotNet" Version="0.13.5.2136" />
14+
</ItemGroup>
15+
16+
</Project>

BenchmarkDotNet8/BenchmarkDotNet8.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNet8", "BenchmarkDotNet8.csproj", "{FE763EA8-DE45-404E-AA17-B8047CE5681C}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{FE763EA8-DE45-404E-AA17-B8047CE5681C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{FE763EA8-DE45-404E-AA17-B8047CE5681C}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{FE763EA8-DE45-404E-AA17-B8047CE5681C}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{FE763EA8-DE45-404E-AA17-B8047CE5681C}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal

BenchmarkDotNet8/Program.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System.Reflection;
2+
using BenchmarkDotNet.Attributes;
3+
using BenchmarkDotNet.Columns;
4+
using BenchmarkDotNet.Jobs;
5+
using BenchmarkDotNet.Running;
6+
7+
BenchmarkRunner.Run<Benchmarks>();
8+
9+
[SimpleJob(RuntimeMoniker.Net70, baseline: true)]
10+
[SimpleJob(RuntimeMoniker.Net80)]
11+
[HideColumns(Column.Job, Column.RatioSD)]
12+
public class Benchmarks
13+
{
14+
private readonly List<int> _numbers = Enumerable.Range(0, 10000).Select(s => Random.Shared.Next()).ToList();
15+
private readonly string _text1 = "Hello woRld! ThIs is a test.It CoUlD be a lot longer, but it'S not. Or is it?";
16+
private readonly string _text2 = "Hello world! This is a test.it could be a lot longer, but it's not. Or is it?";
17+
18+
[Benchmark]
19+
public bool EqualsOrdinalIgnoreCase() => _text1.Equals(_text2, StringComparison.OrdinalIgnoreCase);
20+
21+
[Benchmark]
22+
public bool EqualsOrdinal() => _text1.Equals(_text2, StringComparison.Ordinal);
23+
24+
[Benchmark]
25+
public bool ContainsOrdinalIgnoreCase() => _text1.Contains("Or is it?", StringComparison.OrdinalIgnoreCase);
26+
27+
[Benchmark]
28+
public bool ContainsOrdinal() => _text1.Contains("Or is it?", StringComparison.Ordinal);
29+
30+
[Benchmark]
31+
public bool StartsWithOrdinalIgnoreCase() => _text1.StartsWith("Hello World", StringComparison.OrdinalIgnoreCase);
32+
33+
[Benchmark]
34+
public bool StartsWithOrdinal() => _text1.StartsWith("Hello World", StringComparison.Ordinal);
35+
36+
[Benchmark]
37+
public int LinqMin() => _numbers.Min();
38+
39+
[Benchmark]
40+
public int LinqMax() => _numbers.Max();
41+
42+
[Benchmark]
43+
public int ReflectionCreateInstance() => (int)Activator.CreateInstance(typeof(int));
44+
45+
[Benchmark]
46+
public string InvokeMethodViaReflection()
47+
{
48+
var method = typeof(string).GetMethod("ToLowerInvariant", BindingFlags.Public | BindingFlags.Instance);
49+
return (string)method.Invoke(_text1, null);
50+
}
51+
52+
[Benchmark]
53+
public DayOfWeek EnumParse() => Enum.Parse<DayOfWeek>("Saturday");
54+
55+
[Benchmark]
56+
public DayOfWeek[] EnumGetValues() => Enum.GetValues<DayOfWeek>();
57+
58+
[Benchmark]
59+
public string[] EnumGetNames() => Enum.GetNames<DayOfWeek>();
60+
}

BenchmarkDotNet8/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# .NET 8 Performance Edition
2+
3+
As with every .NET release, Microsoft improves the performance of the runtime and guess what: This release is no exception to this. In this blog post, I want to go through some of the improvements made so far (.NET 8 preview 3).
4+
5+
Found [here](https://steven-giesel.com/blogPost/f6504300-7bf0-48d2-8a14-ba4e2bbea02e)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Contains all of my examples from various blog posts. You can find a comprehensiv
44

55
| BlogPost | Publish Date |
66
| -------------------------------------------------------------------------------------------------------------- | ------------ |
7+
| [.NET 8 Performance Edition](BenchmarkDotNet8/) | 12.04.2023 |
78
| [Creating a ToolTip Component in Blazor](BlazorToolTip/) | 31.03.2023 |
89
| [C# Source Generators: How to get build information?](BuildInformation/) | 26.03.2023 |
910
| [Write your own AutoMapper in C#](AutoMapper/) | 18.03.2023 |

0 commit comments

Comments
 (0)