Does multi-threading improve performance? How?

后端 未结 2 1060
萌比男神i
萌比男神i 2020-12-03 08:54

I hear everyone talking about how multi-threading can improve performance. I don\'t believe this, unless there is something I\'m missing. If I have an array of 100 elements

2条回答
  •  生来不讨喜
    2020-12-03 09:16

    For CPU bound tasks where you have more than one core in your processor you can divide your work on each of your processor core. If you have two cores, split the work on two threads. This way you have to threads working at full speed. However threads are really expensive to create, so you need a pretty big workload to overcome the initial cost of creating the threads.

    You can also use threads to improve appeared performance (or responsiveness) in an interactive application. You run heavy computations on a background thread to avoid blocking UI interactions. Your computations does not complete faster, but your application does not have those "hangs" that make it appear slow and unresponsive.

提交回复
热议问题