Skip to content

Instantly share code, notes, and snippets.

View xoofx's full-sized avatar
🏠
Working from home

Alexandre Mutel xoofx

🏠
Working from home
View GitHub Profile
@xoofx
xoofx / dotnet-releaser-coverage-badge-xoofx-FixedStrings.svg
Last active February 9, 2024 08:18
dotnet-releaser-coverage-badges
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".txt" #>
<#
var vectors = new [] { "Vector64", "Vector128", "Vector256", "Vector512", "Vector", "Vector2", "Vector3", "Vector4" };
var templates = new string[0];
string genT;
@xoofx
xoofx / SepBenchAMD7840HS.md
Last active September 8, 2023 17:06
Sep benchmarks for GTR7 7840HS

Commit https://github.com/nietras/Sep/tree/46d20139bf2e1f9ca01933ff9ca728873fe790cc

BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.22621.819/22H2/2022Update/SunValley2)
AMD Ryzen 7 7840HS w/ Radeon 780M Graphics, 1 CPU, 16 logical and 8 physical cores
.NET SDK=8.0.100-preview.7.23376.3
  [Host]     : .NET 8.0.0 (8.0.23.37506), X64 RyuJIT AVX2
  Job-WASKMK : .NET 7.0.10 (7.0.1023.36312), X64 RyuJIT AVX2
 Job-PLCXMZ : .NET 8.0.0 (8.0.23.37506), X64 RyuJIT AVX2
@xoofx
xoofx / BatchFinder.cs
Last active July 12, 2023 17:08
Optimized AVX2 version of finding the index of an integer from an array
// Discussion about https://mastodon.social/@denisio@dotnet.social/110644302160625267
// Optimized version using AVX. From 4x to 10x faster than a simple version.
// - nint for indexing
// - Unsafe.Add
// - Unrolling of 4 Vector256 + Or of the results to have only 1 branch per loop
// - Finding the local index within the Vector256 without a loop using AVX movemask
// Similar code can be done for Vector128
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@xoofx
xoofx / SepBenchARM64.md
Last active July 20, 2023 16:44
Sep benchmarks on ARM64

Commit c6a06151caca9a318891e583f6341b1a707ee408

BenchmarkDotNet=v0.13.5, OS=Windows 11 (10.0.22621.1702/22H2/2022Update/SunValley2)
Snapdragon Compute Platform, 1 CPU, 8 logical and 8 physical cores
.NET SDK=7.0.302
  [Host]     : .NET 7.0.5 (7.0.523.17405), Arm64 RyuJIT AdvSIMD
  Job-BBZNUX : .NET 7.0.5 (7.0.523.17405), Arm64 RyuJIT AdvSIMD
 Job-IJWXNS : .NET 7.0.5 (7.0.523.17405), Arm64 RyuJIT AdvSIMD
@xoofx
xoofx / BenchHashCodeVsFNV1A.cs
Last active October 29, 2022 06:21
Small benchmark to decide until which size FNV-1A is better than System.HashCode.
using BenchmarkDotNet.Attributes;
using System.Runtime.CompilerServices;
/// <summary>
/// Small benchmark to decide until which size I can use FNV-1A vs System.HashCode.
///
/// Verdict: If the size is lower than 28, FNV-1A is better on .NET 7
/// On .NET 6, it's more above 64 bytes.
///
/// BenchmarkDotNet=v0.13.2, OS=Windows 11 (10.0.22000.1098/21H2)
/// AMD Ryzen 9 5950X, 1 CPU, 32 logical and 16 physical cores
@xoofx
xoofx / BenchWindowsTerminal.cs
Last active December 28, 2021 06:48
Bench Windows Terminal with a wall of 24-bits RGB ANSI scrolling chars
// Bench Windows Terminal with a wall of 24-bits RGB ANSI scrolling chars
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
var width = Console.WindowWidth;
var height = Console.WindowHeight;
var total = width * height;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@xoofx
xoofx / BenchDuffsDeviceMemoryCopy.cs
Created December 11, 2021 19:45
BenchDuffsDeviceMemoryCopy.cs
// Twitter discussion https://twitter.com/nietras1/status/1469740763760181250
// Benchmark of DuffsDevice mem copy vs plain Unsafe.CopyBlock
// | Method | BufferSize | Mean | Error | StdDev |
// |--------------- |----------- |-----------:|----------:|----------:|
// | BenchDuffs | 8 | 2.627 ns | 0.0227 ns | 0.0213 ns |
// | BenchBlockCopy | 8 | 2.608 ns | 0.0160 ns | 0.0150 ns |
// | BenchDuffs | 32 | 2.889 ns | 0.0184 ns | 0.0172 ns |
// | BenchBlockCopy | 32 | 2.394 ns | 0.0132 ns | 0.0123 ns |
// | BenchDuffs | 128 | 6.083 ns | 0.0261 ns | 0.0231 ns |
// | BenchBlockCopy | 128 | 3.904 ns | 0.0223 ns | 0.0208 ns |
@xoofx
xoofx / BuildtimeOptimizedRoslynSourceGenerator.cs
Last active December 10, 2022 14:03
Roslyn Source Generator optimized for build time only usage
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using Microsoft.CodeAnalysis.Text;
namespace SourceGenLib
@xoofx
xoofx / UnpackBenchmarks.cs
Created March 16, 2021 08:15
Unpack variable 1-4 int
// From Twitter discussion: https://twitter.com/firstdrafthell/status/1371704847783895042
//
// | Method | Mean | Error | StdDev |
// |----------------------------- |----------:|----------:|----------:|
// | TestUnpack | 25.454 ns | 0.1450 ns | 0.1356 ns |
// | TestUnpack2 | 25.033 ns | 0.0853 ns | 0.0798 ns |
// | TestUnpackWithSpan | 6.936 ns | 0.0535 ns | 0.0500 ns |
// | TestUnpackWithSpanStackAlloc | 8.733 ns | 0.1149 ns | 0.1075 ns |
using System;
using System.Buffers.Binary;