Skip to content

Instantly share code, notes, and snippets.

View megasuperlexa's full-sized avatar
♠️
Focusing

megasuperlexa

♠️
Focusing
View GitHub Profile
┌──count()─┐
│ 11849659 │
└──────────┘
@megasuperlexa
megasuperlexa / Program.cs
Created March 17, 2024 08:59
Array pool perf
using System.Buffers;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
public class Program
{
private static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<PoolBench>();
}
using System;
BadMethod(1,2);
BadMethod(2,1); // bang!
GoodMethod(2,1); // tadam
var uid = (UserId)1;
var accid = (AccountId)2;
@megasuperlexa
megasuperlexa / 1.cs
Last active March 23, 2018 09:12
Memoize example
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
public static class Program
{
public static Func<T, V> MemoizeExt<T, V>(this Func<T, V> f) => a =>
new ConcurrentDictionary<T, V>().GetOrAdd(a, f);
public static Func<T, V> Memoize<T, V>(Func<T, V> f) => a =>