This project is playground for various benchmarks. Creating benchmark is much easier than reading IL and guessing performance characteristics. Be aware that IL is just one part of puzzle, keep in mind there's JITter as well and other factors, such as CPU caching, GC, ...
If you can explain benchmark results/you can link to documentation, feel free to submit an issue or PR with explanation/link.
Only results are listed - interpretation of results is up to the readers themselves.
Not all benchmarks may be listed, check source directly.
- Get Assembly Version: demonstrating how impactful it is to get custom attribute over and over
- Bitmap access: determining the fastest approach for implementing bitmap
- Division by
n
: comparing modulo with logical AND when dividing by even number - Using lambdas: comparing different ways how to write lambdas/anonymous functions
- String builder append:
comparing
StringBuilder.Append
when concatenating simple string - String concatenation: simple concat of two strings
- Formatting string while rendering just part of it:
comparing approaches to format string in combination of
string.Substring
- Throw or return: demonstrating price of throwing an exception
- Reading country code from culture string: what's the fastest way to read country code from culture string?
- Comparing two strings:
comparing
==
operator andstring.Equals
method
- Add to collection:
comparing different ways to add entry to collection (List/Dictionary with default capacity and with capacity set to
n
) - Add to
ConcurrentBag
andConcurrentDictionary
: demonstrating price of adding to concurrent collection when concurrency is not needed (e.g. after refactoring) - Add to
ConcurrentBag
: demonstrating price of creatingConcurrentBag<>
with known initial data - Collection Contains ...:
comparing
corefx
immutable collections with collections fromLanguageExt.Core
- - Collection Create:
comparing
corefx
immutable collections instantiation/creation withLanguageExt.Core
(ctor
,.Create
) - Creating empty collection:
comparison of creating empty
List
andDictionary
- Array access: determining the fastest way to access array item (and way of iteration)
- Array/Array as
IEnumerable
/List
foreach
: difference between iterating over array andList
usingforeach
- Accessing array/
List<>
value using indexer: comparison of accessing value via[]
on array andList<>
- Deconstructing
KeyValuePair<,>
: finding difference of using key value pair deconstruction - Deconstructing
KeyValuePair<,>
vs accessing value using key: determining price of accessing value using key instead of simple iteration - Differences enumerating
IEnumerable
: demonstrating difference ofIEnumerable
implementation - Enumerating
ImmutableArray
various way: finding difference of various enumeration approaches onImmutableArray
- Collection Lookup:
benchmark of lookup of structured value (e.g.
Id
), comparing array,List<T>
andDictionary<TKey, TValue>
- Creating array or
List<>
from collection: benchmark comparing performance of.ToArray()
and.ToList()
- Creating
Dictionary<,>
from collection: benchmark of creating dictionary out of collection using LINQ and simple implementation - Codebook lookup: different ways of looking up value in short codebook
- Creating/parsing
AuthorizationHeaderValue
: comparing performance of parsing authorization header value or using ctor
- JSON Deserialization:
observing memory allocation by
StreamReader
buffer
- System.Text.Json.JsonDocument serialization
benchmark of serialization of
System.Text.Json.JsonDocument
- System.Text.Json.JsonDocument to MongoDB.Bson.BsonDocument benchmark of conversion of JSON to BSON document
dotnet run -c Release --project src/Benchmarkator -f net6.0
... so running benchmarks related to collections is done using command:
dotnet run -c Release --project src/Benchmarkator -f net6.0 --filter Benchmarkator.Collections*
More about running benchmarks: BenchmarkDotNet | How to use console arguments.