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?
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.
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. , , " ", ( ).
. , .
- , , EXCEPT, , , / , . - , . - .
" , ". , , ( ), . , , , , , .
, , , 1000; 4 ; 2500 , 2 , ( 1000 ).
:
( , , , - , . 4 , , 2 )
task parallel library/Rx , System.Threading.ThreadPool, .
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.
Source: https://habr.com/ru/post/1737119/More articles:Опрос SharePoint: Как определить поля вопроса при получении информации обследований из веб-сервиса "Списки"? - web-servicesIs there a reason we are not using subclasses of UIImageView? - asynchronousMaven-ear-plugin - excluding several modules, i.e. Banks, wars, etc. - javacURL + HTTP_POST, получите 500 ошибок. Не знаю? - postAdding listeners at runtime? - Java MVC - javaHow to make Visual C ++ 9 not emit code that actually never gets called? - c ++How can I use SSRS ReportViewer from VS 2008 in VS2010 project? - visual-studio-2008To catch or not to catch - c ++Какая оптимальная конфигурация оборудования для приложения LAMP с большой нагрузкой - performanceNullable Date column merge error - javaAll Articles