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 / MethodCall_SealedVsNonSealedVsVirtual_Benchmark.cs
Last active January 27, 2025 23:13
Benchmark to measure performance difference between calling overridden methods on: open vs sealed classes
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
/// <summary>
/// Refer to the README.MD for details about:
/// 1. description of each benchmark
/// 2. results
/// 3. analysis of the results
///
/// </summary>
@udlose
udlose / Linq to Xml - XName Atomization Benchmark.cs
Created January 12, 2025 21:29
Linq to Xml - XName Atomization Benchmark
void Main()
{
var summary = BenchmarkRunner.Run<LinqToXmlXNameAtomizationBenchmark>();
// xml test data
//<aw:Root xmlns:aw="http://www.adventure-works.com">
// <aw:Data ID="1">4,100,000</aw:Data>
// <aw:Data ID="2">3,700,000</aw:Data>
// <aw:Data ID="3">1,150,000</aw:Data>
//</aw:Root>
@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(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_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_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]
@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 / 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 / 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 / SpanIndexOfBenchmark.cs
Created March 13, 2026 16:06
SpanIndexOfBenchmark
// run with:
// dotnet run -c Release --framework net10.0 -- --filter *
// * Summary *