An open API service indexing awesome lists of open source software.

https://github.com/mjebrahimi/dotnet-collections-benchmark

🚀 A comprehensive performance comparison benchmark between different .NET collections.
https://github.com/mjebrahimi/dotnet-collections-benchmark

benchmark benchmarking benchmarks big-o big-o-notation big-o-notation-algorithm big-o-performance collection collections csharp data-structure data-structures data-structures-algorithms data-structures-and-algorithms datastructure datastructures datastructures-algorithms dotnet performance

Last synced: about 1 month ago
JSON representation

🚀 A comprehensive performance comparison benchmark between different .NET collections.

Awesome Lists containing this project

README

        

![.NET Collections Benchmark](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/repository-image.png)

# .NET Collections Benchmark

A comprehensive performance comparison benchmark between different .NET collections.

> If you are working with small collections (e.g. 100 items) or your code is not HOT path (not executed frequently), it's not a big deal and you usually don't need to worry about your collection's performance. (It's better not to waste your time with premature micro-optimizations)
>
> However, if you are dealing with Large collections (e.g. 100K, 1M, or more items) or your code is HOT path (executed frequently), you should be obsessed with performance and choosing the best collection type based on your needs and conditions.
>
> This benchmark report helps you to choose the best collection type in terms of performance based on your needs and conditions.

## Give it a Star! ⭐️

If you find this repository useful and like it, why not give it a star? if not, never mind! :)

## Benchmarks

- [Benchmark of Collection Searching (Contains method) in terms of Execution Time (Mean)](#benchmark-of-collection-searching-contains-method-in-terms-of-execution-time-mean)
- [Benchmark of Collection Searching (Contains method) in terms of Allocation Size](#benchmark-of-collection-searching-contains-method-in-terms-of-allocation-size)
- [Benchmark of Collection Initializing in terms of Execution Time (Mean)](#benchmark-of-collection-initializing-in-terms-of-execution-time-mean)
- [Benchmark of Collection Initializing in terms of Allocation Size](#benchmark-of-collection-initializing-in-terms-of-allocation-size)
- [Benchmark of Collection Searching (TryGetValue method) in terms of Execution Time (Mean)](#benchmark-of-collection-searching-trygetvalue-method-in-terms-of-execution-time-mean)
- [Benchmark of Collection Searching (TryGetValue method) in terms of Allocation Size](#benchmark-of-collection-searching-trygetvalue-method-in-terms-of-allocation-size)

### Benchmark of Collection Searching (Contains method) in terms of Execution Time (Mean)

- **Visit [HTML Page](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-SearchContains-Mean.html)**
- **Visit [Full Image](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-SearchContains-Mean.png)**

![Benchmark-SearchContains-Mean-Preview](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-SearchContains-Mean-Preview.png)

### Benchmark of Collection Searching (Contains method) in terms of Allocation Size

- **Visit [HTML Page](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-SearchContains-Allocated.html)**
- **Visit [Full Image](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-SearchContains-Allocated.png)**

![Benchmark-SearchContains-Allocated-Preview](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-SearchContains-Allocated-Preview.png)

### Benchmark of Collection Initializing in terms of Execution Time (Mean)

- **Visit [HTML Page](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-Initialize-Mean.html)**
- **Visit [Full Image](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-Initialize-Mean.png)**

![Benchmark-Initialize-Mean-Preview](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-Initialize-Mean-Preview.png)

### Benchmark of Collection Initializing in terms of Allocation Size

- **Visit [HTML Page](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-Initialize-Allocated.html)**
- **Visit [Full Image](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-Initialize-Allocated.png)**

![Benchmark-Initialize-Allocated-Preview](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-Initialize-Allocated-Preview.png)

### Benchmark of Collection Searching (TryGetValue method) in terms of Execution Time (Mean)

- **Visit [HTML Page](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-SearchTryGetValue-Mean.html)**
- **Visit [Full Image](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-SearchTryGetValue-Mean.png)**

![Benchmark-SearchTryGetValue-Mean-Preview](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-SearchTryGetValue-Mean-Preview.png)

### Benchmark of Collection Searching (TryGetValue method) in terms of Allocation Size

- **Visit [HTML Page](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-SearchTryGetValue-Allocated.html)**
- **Visit [Full Image](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-SearchTryGetValue-Allocated.png)**

![Benchmark-SearchTryGetValue-Allocated-Preview](https://mjebrahimi.github.io/DotNet-Collections-Benchmark/Benchmark-SearchTryGetValue-Allocated-Preview.png)

## BenchmarkDotNetVisualizer🌈

All the benchmarks are created by [BenchmarkDotNetVisualizer](https://github.com/mjebrahimi/BenchmarkDotNetVisualizer).

## Todo

- [ ] Add .NET 9.0 **OrderedDictionary** to the benchmarks
- [ ] Add benchmarks for other operations such as **Add**, **Insert**, **Remove**, and **Update**.

## Useful Resources

- [.NET Big-O Algorithm Complexity Cheat Sheet](https://github.com/RehanSaeed/.NET-Big-O-Algorithm-Complexity-Cheat-Sheet)