Threading cost - minimum runtime when threads add speed

I am working on a C # application that works with an array. It passes through it (this means that at one time only a narrow part of the array is used). I am considering adding threads to it to speed up execution (it runs on a dual-core computer). The problem is that I don’t know if this will really help, because the threads are worth something, and this cost can easily be more than parallel gain ... So, how can I determine if threading will help?

+3
source share
5 answers

Try to write some tests that most accurately simulate the real conditions in which your software will actually be used.

Check and run the single-threaded version. Check and run the multithreaded version. Compare the two sets of results.

+6
source

If your application is connected to the CPU (i.e. does not waste time reading files or waiting for data from the device), and there is practically no real-time data exchange (data changes if you read it only its penalty) between threads, then you can significantly increase the speed by 50-> 75% by adding another stream (while it still remains, of course, combined with the CPU).

The main overhead for multithreading comes from 2 places.

  • . , , , , , , . - , .

  • . , , (, ). , , , . . , , . , , .

, , , , , , ( , , , -/ ). , ( , ).

: , , ( , , ).

P.S. , , " ", ( ).

+4

. , .

- , , EXCEPT, , , / , . - , . - .

" , ". , , ( ), . , , , , , .

, , , 1000; 4 ; 2500 , 2 , ( 1000 ).

+1

:

  • Sysinternals Process Monitor
  • ( Visual Studio).
  • " "
  • , .
  • 50% , , , , ( , , - , ).

( , , , - , . 4 , , 2 )

task parallel library/Rx , System.Threading.ThreadPool, .

+1

imho , . :

  • . "", .
  • , / . , .

Anyway, ignoring my point 1 - where you can go multi-threaded without speeding things up so your user interface is responsive - I would say that it is always faster when you can actually share the work (so you can save more than one busy core) or unload it for reasons.

0
source

Source: https://habr.com/ru/post/1737119/


All Articles