Know Your Data05/24/2026
There are many social posts, blog posts, and code suggestions online for .NET code snippets titled "Use X instead of Y" or "Why X is better than Y". These posts usually (but not always) include a basic performance comparison using BenchmarkDotNet to validate their catchy titles.
At first glance, these suggestions appear justified by the measurements. However, upon closer inspection, many important details are typically excluded:
- What version of .NET (SDK and Runtime) was used?
- What version of OS was used?
- What is the underlying hardware architecture (ARM or x64)?
- Does the hardware support vectorized operations?
- What are the sizes of the vector registers?
- What is the memory read latency?
- What are the CPU cache sizes?
- What branch prediction algorithm does the CPU use?
- What are the input data types (structs, classes, primitives)?
- What is the input data structure?
- What is the size of the input data (bytes/array length)?
- What is the data access pattern?
- And many more factors
Since explaining all these factors is beyond this post's scope, I will focus on data access patterns and data sizes. For those interested in a deeper analysis, I recommend reading Pro .NET Benchmarking by Andrey Akinshin, which explains many common pitfalls.