C# – Convert an array to a list

The simplest way to convert an array to a list is with the ToList() Linq method: This outputs the following: Besides using ToList(), you can also use the list constructor or AddRange(). Before I show those, I’ll explain why you’d want to use these special methods instead of just adding items individually to a new … Read more

Comparing performance with Benchmark.NET graphs

The following graph compares the execution time of three sort implementations ran against varying input sizes (1k, 10k, 100k): This graph was generated using Benchmark.NET, which I’ll show how to use in this article. I’ll be comparing the performance of multithreaded quicksort implementations (with the non-threaded Array.Sort() as a baseline). Create console app and reference … Read more

Multithreaded quicksort in C#

One day I decided to challenge myself by trying to implement multithreaded quicksort. I wanted to see how it would compare to the built-in Array.Sort() method. I came up with two algorithms that were 2-4x faster than Array.Sort(): After continuing to tinker, in attempts to further optimize, I came across the AsParallel().OrderBy() method (PLINQ). After … Read more