When will parallel increase performance

前端 未结 5 655
你的背包
你的背包 2021-02-06 16:11

I\'m trying to understand when the usage of parallel will increase the performance.
I tested it with a simple code that ran over 100,000 items in List<

5条回答
  •  情歌与酒
    2021-02-06 16:45

    Parallelism helps performance only to the extent that it lets you get all your hardware cranking in a useful direction.

    Two CPU-bound threads will not be faster than one if they have to share a single core. In fact, they will be slower.

    There are other reasons than performance for using multiple threads. For example, web applications, that have to interact with many simultaneous users, can be written as a single thread that just responds to interrupts. However, it simplifies the code enormously if it can be written with threads.

    That doesn't make the code any faster. It makes it easier to write.

提交回复
热议问题