Post by account_disabled on Dec 6, 2023 19:25:38 GMT -8
Thread synchronization overhead I changed the project configuration to Release. In the next step I could start the project but attention! to reduce the influence of other processes on the test results e.g. debug mode with Visual Studio I did it from the command line. As a result of running multiple tests were performed and at the end I received a table with the following results Table concurrency The trap of naive optimization Then I wanted to measure the time it takes to generate the same list of prime numbers in a parallel manner. For this purpose I added an appropriately modified method to the BenchmarkTest class. Instead of the Enumerable class I used ParallelEnumerable whose Range method generates a parallel sequence of integral numbers Concurrency in the application After running the program BenchmarkDotNet measured the average execution time for each of the two methods.
The results were as follows Concurrency in the application As you can see the parallelized task was completed in approximately times longer than the sequentially executed task. Where could this come from? Meanders of parallelism Microsoft explains on the Understanding Speedup Email Marketing List in PLINQ website that one of the reasons for the failure of optimization by parallelization is the occurrence of a certain time overhead needed to synchronize tasks between threads. This phenomenon can be observed by analyzing the record of system events which in Windows are called Event Tracing for Windows.
To collect and analyze these events I used Concurrency Visualizer for Visual Studio which is an addon for Visual Studio at the time of writing this article there was no addin for Visual Studio. To facilitate the analysis of events generated by Concurrency Visualizer I temporarily gave up running the analyzed code through BenchmarkDotNet and instead ran one of the tested methods only once first the sequential version then the multithreaded version.
The results were as follows Concurrency in the application As you can see the parallelized task was completed in approximately times longer than the sequentially executed task. Where could this come from? Meanders of parallelism Microsoft explains on the Understanding Speedup Email Marketing List in PLINQ website that one of the reasons for the failure of optimization by parallelization is the occurrence of a certain time overhead needed to synchronize tasks between threads. This phenomenon can be observed by analyzing the record of system events which in Windows are called Event Tracing for Windows.
To collect and analyze these events I used Concurrency Visualizer for Visual Studio which is an addon for Visual Studio at the time of writing this article there was no addin for Visual Studio. To facilitate the analysis of events generated by Concurrency Visualizer I temporarily gave up running the analyzed code through BenchmarkDotNet and instead ran one of the tested methods only once first the sequential version then the multithreaded version.