Skip to content

Instantly share code, notes, and snippets.

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

Marc Gravell mgravell

🏠
Working from home
View GitHub Profile
@mgravell
mgravell / results.txt
Last active September 25, 2025 09:07
sha1 vs xxhash3
BenchmarkDotNet v0.15.4, Linux Ubuntu 25.04 (Plucky Puffin)
Intel Core Ultra 7 155U 0.40GHz, 1 CPU, 14 logical and 12 physical cores
.NET SDK 9.0.110
[Host] : .NET 9.0.9 (9.0.9, 9.0.925.41916), X64 RyuJIT x86-64-v3
DefaultJob : .NET 9.0.9 (9.0.9, 9.0.925.41916), X64 RyuJIT x86-64-v3
| Method | Length | Mean | Error | StdDev | Ratio | RatioSD | Allocated | Alloc Ratio |
|-------- |--------- |-----------------:|---------------:|-----------------:|------:|--------:|----------:|------------:|
| SHA1 | 1024 | 1,038.23 ns | 20.541 ns | 19.214 ns | 1.00 | 0.03 | - | NA |
using System.Runtime.CompilerServices;
Foo foo = new Foo(5,6,7,8);
// scenario (why we're here): the GetRef method doesn't compile :(
// you cannot conveniently use by-ref return from struct methods
// or properties, because "this" is has scoped-like semantics;
// ("scoped" can be paraphrazed as "this reference is not captured
// or returned", i.e. it doesn't risk exposing the reference later)
@mgravell
mgravell / intro.md
Last active August 27, 2025 16:27
SE.Redis v3 core rework status

What is this

SE.Redis; working on stability+performance work - basically: removing all of "pipelines", "arenas", and a bunch of other things that are a decade of cumulative hacks, to a re-architected implementation designed from first principles with all the good things that didn't exist way back in the never.

Also, adding features and removing tech debt:

  • cancellation supported from the outset on both sync+async paths
  • zero-alloc routes if you can use a new API (damn you, Task!)
using System;
using System.IO;
using System.Linq;
Checkerboard.DrawCheckerboard(Console.Out, 5);
Console.WriteLine();
Checkerboard.DrawCheckerboard(Console.Out, 8);
Console.WriteLine();
static class Checkerboard
BenchmarkDotNet v0.14.0, Windows 11 (10.0.26120.1350)
AMD Ryzen 9 7900X, 1 CPU, 24 logical and 12 physical cores
.NET SDK 8.0.203
[Host] : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
DefaultJob : .NET 8.0.7 (8.0.724.31311), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
| Method | Number | Mean | Error | StdDev | Median |
|------- |------- |----------:|----------:|----------:|----------:|
| Fixed | 8 | 0.6012 ns | 0.0042 ns | 0.0037 ns | 0.6014 ns |
string src = "abc";
foreach (var chunk in src.Find(42))
{
// woohoo, this compiles!
}
static class MyHelperExtensions
{
// just exists to make the API available; "notImportant" is *all* of your
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
BenchmarkRunner.Run<PunBench>();
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.Threading.Tasks;
#if DEBUG
var obj = new AsyncMachineryBenchmarks();
// we should have done 100 things (just yields) either way
@mgravell
mgravell / Program.cs
Created January 25, 2024 14:09
float parsing
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Buffers;
using System.Text.Json;
// prove impl
var obj = new MyBench { Count = 5 };
obj.Init();
Console.WriteLine(obj.Payload);
Console.WriteLine(string.Join(',', obj.Linq()));
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Numerics;
BenchmarkRunner.Run(typeof(ConcatBenchmark).Assembly);
[MemoryDiagnoser]
public class ConcatBenchmark
{
private readonly int[] arr1 = new[] { 1, 2, 3, 4, 5, 0 },