Moving_avg_concurrent2 performance
Moving_avg_concurrent2 does not scale because the overhead of creating and managing multiple goroutines outweighs the benefits of parallelism. Goroutines are lightweight threads, but they still have some overhead associated with them, such as the cost of creating and scheduling the goroutine, and the cost of communicating between goroutines. In this case, the overhead of managing the goroutines is greater than the benefit of parallelizing the computation.
Moving_avg_concurrent3 performance
Moving_avg_concurrent3 is slower than moving_avg_serial4 because it uses a master/worker paradigm, which introduces additional overhead. In the master/worker paradigm, the master thread creates a pool of worker threads and then distributes the work to the workers. The workers then perform the computation and return the results to the master thread. This introduces additional overhead because the master thread has to create and manage the worker threads, and the workers have to communicate with the master thread to receive the work and return the results.
Conclusion
In this case, it is not possible to achieve a significant performance improvement by parallelizing the computation. The overhead of managing the goroutines outweighs the benefits of parallelism. It is better to use a serial implementation of the algorithm, such as moving_avg_serial4.
The above is the detailed content of Why Doesn't Parallelization Improve Performance in This Moving Average Calculation?. For more information, please follow other related articles on the PHP Chinese website!