December 2019
Intermediate to advanced
346 pages
9h 8m
English
Throughout this book, we used the Enumerable.Range() method to generate a sequence of numbers. We can generate numbers in parallel as well using the ParallelEnumerable class. Let's do a simple test comparison between Enumerable and the ParallelEnumerable class:
Stopwatch watch = Stopwatch.StartNew();IEnumerable<int> parallelRange = ParallelEnumerable.Range(0, 5000).Select(i => i);watch.Stop();Console.WriteLine($"Time elapsed {watch.ElapsedMilliseconds}");Stopwatch watch2 = Stopwatch.StartNew();IEnumerable<int> range = Enumerable.Range(0, 5000);watch2.Stop();Console.WriteLine($"Time elapsed {watch2.ElapsedMilliseconds}");Console.ReadLine();
The output is as follows:
As you can see, ParallelEnumerable works much faster ...
Read now
Unlock full access