Skip to content

Commit

Permalink
refactor: c# 12, .net 8, upgraded all dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
paviad committed Jul 26, 2024
1 parent 88c5e93 commit 80776df
Show file tree
Hide file tree
Showing 179 changed files with 10,921 additions and 12,367 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<head>
<meta charset='utf-8' />
<title>Benchmarks.BufferWriting-20201110-192311</title>

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }
</style>
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<head>
<meta charset='utf-8' />
<title>Benchmarks.ImmutableDictionaryLookup-20200714-200711</title>

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }
</style>
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<head>
<meta charset='utf-8' />
<title>Benchmarks.LockOverhead-20200825-220153</title>

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }
</style>
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<head>
<meta charset='utf-8' />
<title>Benchmarks.MaxValueToDepth-20200823-173129</title>

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }
</style>
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<head>
<meta charset='utf-8' />
<title>Benchmarks.MemoryCopy-20200823-155139</title>

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }
</style>
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<head>
<meta charset='utf-8' />
<title>Benchmarks.PlainVsCursorStruct-20200726-153143</title>

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }
</style>
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<head>
<meta charset='utf-8' />
<title>Benchmarks.PropertiesVsFields-20200825-210502</title>

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }

<style type="text/css">
table { border-collapse: collapse; display: block; width: 100%; overflow: auto; }
td, th { padding: 6px 13px; border: 1px solid #ddd; text-align: right; }
tr { background-color: #fff; border-top: 1px solid #ccc; }
tr:nth-child(even) { background: #f8f8f8; }
</style>
</head>
<body>
Expand Down
7 changes: 6 additions & 1 deletion MarcusW.VncClient.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=WpfVncClient_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=WpfVncClient_002EAnnotations/@EntryIndexedValue">True</s:Boolean>




</wpf:ResourceDictionary>
22 changes: 10 additions & 12 deletions benchmarks/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
</ItemGroup>

</Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
</ItemGroup>
</Project>
143 changes: 71 additions & 72 deletions benchmarks/Benchmarks/BufferWriting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,94 @@
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;

namespace Benchmarks
namespace Benchmarks;

public class BufferWriting
{
public class BufferWriting
private readonly byte[] _buffer = new byte[1920 * 1080 * 4];

[Benchmark]
public void ArrayIndexer()
{
private readonly byte[] _buffer = new byte[1920 * 1080 * 4];
for (var i = 0; i < _buffer.Length; i += 4)
SetPixelArrayIndexer(_buffer, i, 0xffffffff);
}

[Benchmark]
public void ArrayIndexer()
[Benchmark]
public unsafe void Pointer()
{
fixed (byte* ptr = &_buffer[0])
{
for (int i = 0; i < _buffer.Length; i += 4)
SetPixelArrayIndexer(_buffer, i, 0xffffffff);
for (var i = 0; i < _buffer.Length; i += 4)
SetPixelPointer(ptr + i, 0xffffffff);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetPixelArrayIndexer(byte[] buffer, int i, uint color)
[Benchmark]
public unsafe void PointerMemcpy()
{
fixed (byte* ptr = &_buffer[0])
{
buffer[i] = (byte)(color & 0xff);
buffer[i + 1] = (byte)((color >> 8) & 0xff);
buffer[i + 2] = (byte)((color >> 16) & 0xff);
buffer[i + 3] = (byte)((color >> 24) & 0xff);
for (var i = 0; i < _buffer.Length; i += 4)
SetPixelPointerMemcpy(ptr + i, 0xffffffff);
}
}

[Benchmark]
public void Span()
[Benchmark]
public unsafe void PointerReinterpretCast()
{
fixed (byte* ptr = &_buffer[0])
{
Span<byte> buffer = _buffer;

for (int i = 0; i < _buffer.Length; i += 4)
SetPixelSpan(buffer.Slice(i, 4), 0xffffffff);
for (var i = 0; i < _buffer.Length; i += 4)
SetPixelPointerReinterpretCast(ptr + i, 0xffffffff);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetPixelSpan(in Span<byte> span, uint color)
{
span[0] = (byte)(color & 0xff);
span[1] = (byte)((color >> 8) & 0xff);
span[2] = (byte)((color >> 16) & 0xff);
span[3] = (byte)((color >> 24) & 0xff);
}
[Benchmark]
public void Span()
{
Span<byte> buffer = _buffer;

[Benchmark]
public unsafe void Pointer()
{
fixed (byte* ptr = &_buffer[0])
{
for (int i = 0; i < _buffer.Length; i += 4)
SetPixelPointer(ptr + i, 0xffffffff);
}
}
for (var i = 0; i < _buffer.Length; i += 4)
SetPixelSpan(buffer.Slice(i, 4), 0xffffffff);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void SetPixelPointer(byte* ptr, uint color)
{
*ptr++ = (byte)(color & 0xff);
*ptr++ = (byte)((color >> 8) & 0xff);
*ptr++ = (byte)((color >> 16) & 0xff);
*ptr = (byte)((color >> 24) & 0xff);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetPixelArrayIndexer(byte[] buffer, int i, uint color)
{
buffer[i] = (byte)(color & 0xff);
buffer[i + 1] = (byte)((color >> 8) & 0xff);
buffer[i + 2] = (byte)((color >> 16) & 0xff);
buffer[i + 3] = (byte)((color >> 24) & 0xff);
}

[Benchmark]
public unsafe void PointerReinterpretCast()
{
fixed (byte* ptr = &_buffer[0])
{
for (int i = 0; i < _buffer.Length; i += 4)
SetPixelPointerReinterpretCast(ptr + i, 0xffffffff);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void SetPixelPointer(byte* ptr, uint color)
{
*ptr++ = (byte)(color & 0xff);
*ptr++ = (byte)((color >> 8) & 0xff);
*ptr++ = (byte)((color >> 16) & 0xff);
*ptr = (byte)((color >> 24) & 0xff);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void SetPixelPointerReinterpretCast(byte* ptr, uint color)
{
*(uint*)ptr = color;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void SetPixelPointerMemcpy(byte* ptr, uint color)
{
Unsafe.CopyBlock(ptr, &color, sizeof(uint));
}

[Benchmark]
public unsafe void PointerMemcpy()
{
fixed (byte* ptr = &_buffer[0])
{
for (int i = 0; i < _buffer.Length; i += 4)
SetPixelPointerMemcpy(ptr + i, 0xffffffff);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void SetPixelPointerReinterpretCast(byte* ptr, uint color)
{
*(uint*)ptr = color;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private unsafe void SetPixelPointerMemcpy(byte* ptr, uint color)
{
Unsafe.CopyBlock(ptr, &color, sizeof(uint));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void SetPixelSpan(in Span<byte> span, uint color)
{
span[0] = (byte)(color & 0xff);
span[1] = (byte)((color >> 8) & 0xff);
span[2] = (byte)((color >> 16) & 0xff);
span[3] = (byte)((color >> 24) & 0xff);
}
}
49 changes: 20 additions & 29 deletions benchmarks/Benchmarks/ImmutableDictionaryLookup.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,33 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using BenchmarkDotNet.Attributes;

namespace Benchmarks
namespace Benchmarks;

public class ImmutableDictionaryLookup
{
public class ImmutableDictionaryLookup
{
private const int Index = 500;
private readonly IImmutableDictionary<int, object> _dictionary= Enumerable.Range(0, 1000).ToImmutableDictionary(i => i, i => new object());
private const int Index = 500;

[Benchmark]
public object Indexer()
{
if (!_dictionary.ContainsKey(Index))
return null;
return _dictionary[Index];
}
private readonly IImmutableDictionary<int, object> _dictionary =
Enumerable.Range(0, 1000).ToImmutableDictionary(i => i, _ => new object());

[Benchmark]
public object TryGet()
[Benchmark]
public object? Indexer() => CollectionExtensions.GetValueOrDefault(_dictionary, Index);

[Benchmark]
public object? TryCatch()
{
try
{
if (!_dictionary.TryGetValue(Index, out object value))
return null;
return value;
return _dictionary[Index];
}

[Benchmark]
public object TryCatch()
catch
{
try
{
return _dictionary[Index];
}
catch
{
return null;
}
return null;
}
}

[Benchmark]
public object? TryGet() => CollectionExtensions.GetValueOrDefault(_dictionary, Index);
}
Loading

0 comments on commit 80776df

Please sign in to comment.