Skip to content

Instantly share code, notes, and snippets.

View udlose's full-sized avatar
:octocat:
Probably benchmarking...

Dave Black udlose

:octocat:
Probably benchmarking...
View GitHub Profile
@udlose
udlose / ForVsForeach_Benchmark.linq
Last active April 22, 2026 20:24
for vs. foreach iteration over List<Guid>
// LinqPad BenchmarkDotNet script
// Compares for-loop (indexer) vs foreach (struct enumerator) over List<T>
// at sizes relevant to EntryDoor slab definition lists.
//
// Required NuGet: BenchmarkDotNet
//
// NOTE: Set the target framework and runtime in your LinqPad/project settings.
void Main()
{
@udlose
udlose / SpanIndexOfBenchmark.cs
Created March 13, 2026 16:06
SpanIndexOfBenchmark
// run with:
// dotnet run -c Release --framework net10.0 -- --filter *
// * Summary *
@udlose
udlose / IterationBenchmarks_for_vs_foreach_ValueType.linq
Created February 16, 2026 21:30
Benchmark comparing for vs foreach on List<int> using .NET 10 x64 vs .NET Framework 4.8.1 x64 RyuJIT vs .NET Framework 4.8.1 x86 LegacyJIT
[MemoryDiagnoser]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[Config(typeof(IterationBenchmarks_for_vs_foreach_ValueType.IterationBenchmarksConfig))]
public class IterationBenchmarks_for_vs_foreach_ValueType
{
[Params(1_000, 10_000, 50_000)]
public int Count;
private List<int> _listOfInt = null;
private Consumer _consumer = null;
@udlose
udlose / Dictionary_Lookup_Hit_vs_Miss_for_Guid_vs_String.linq
Last active February 9, 2026 00:06
Dictionary Lookup Hit vs Miss for Guid vs string
[MemoryDiagnoser]
public class DictionaryKeyLookupHitBenchmarks
{
private readonly Consumer _consumer = new Consumer();
private Guid[] _guidKeys = Array.Empty<Guid>();
private string[] _string20Keys = Array.Empty<string>();
private string[] _string50Keys = Array.Empty<string>();
private Dictionary<Guid, int> _guidDictionary = new Dictionary<Guid, int>();
@udlose
udlose / Dictionary_Add_with_key_of_type_Guid_vs_string.linq
Created February 2, 2026 16:48
Dictionary Add with key of type Guid vs string
[MemoryDiagnoser]
[Config(typeof(DictionaryKeyAddBenchmarks.DictionaryKeyAddBenchmarksConfig))]
public class DictionaryKeyAddBenchmarks
{
private readonly Consumer _consumer = new Consumer();
private Guid[] _guidKeys = Array.Empty<Guid>();
private string[] _string_20_Keys = Array.Empty<string>();
private string[] _string_50_Keys = Array.Empty<string>();
@udlose
udlose / ArrayList_foreach_object_vs_specific_type_ReferenceType_Benchmarks.linq
Created January 30, 2026 17:36
ArrayList_foreach_object_vs_specific_type_ReferenceType_Benchmarks
[MemoryDiagnoser]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[Config(typeof(IterationBenchmarks.IterationBenchmarksConfig))]
public class IterationBenchmarks
{
[Params(1_000, 10_000, 50_000)]
public int Count;
private ArrayList _arrayList = null;
@udlose
udlose / ArrayList_foreach_vs_List(Person)_foreach_ReferenceType_Benchmarks.linq
Last active January 30, 2026 17:43
.NET Benchmark for comparing iteration using foreach over ArrayList vs List<T> containing Reference Type
[MemoryDiagnoser]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[Config(typeof(IterationBenchmarks.IterationBenchmarksConfig))]
public class IterationBenchmarks
{
[Params(1_000, 10_000, 50_000)]
public int Count;
private ArrayList _arrayList = null;
@udlose
udlose / ArrayList_foreach_vs_List(int)_foreach_ValueType_Benchmarks.linq
Last active January 30, 2026 17:41
.NET Benchmark and Results for comparing iteration using foreach over ArrayList vs List<T> containing Value Type
[MemoryDiagnoser]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
[CategoriesColumn]
[Config(typeof(IterationBenchmarks.IterationBenchmarksConfig))]
public class IterationBenchmarks
{
[Params(1_000, 10_000, 50_000)]
public int Count;
private ArrayList _arrayList = null;
@udlose
udlose / ArrayList_foreach_vs_for_Loop_ReferenceType_Benchmarks.linq
Last active June 8, 2026 15:27
.NET Benchmark and Results for comparing iteration using foreach vs for over ArrayList containing Reference Type
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
[MemoryDiagnoser]
@udlose
udlose / ArrayList_for_vs_foreach_Loop_ValueType_Benchmarks.linq
Last active February 2, 2026 15:14
.NET Benchmark and Results for comparing iteration using foreach vs for over ArrayList containing Value Type
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
[MemoryDiagnoser]