Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does multi-threading improve performance? How?

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 and traversing it takes 6 seconds. When I divide the work between two threads, the processor would have to go through the same amount of work and therefore time, except that they are working simultaneously but at half the speed. Shouldn't multi threading make it even slower? Since you need additional instructions for dividing the work?

like image 696
Valentin Avatar asked Mar 08 '13 11:03

Valentin


People also ask

How does multithreading improve performance?

The ultimate goal of multithreading is to increase the computing speed of a computer and thus also its performance. To this end, we try to optimize CPU usage. Rather than sticking with a process for a long time, even when it's waiting on data for example, the system quickly changes to the next task.

Does multithreading rendering improve performance?

If you're playing VALORANT on a high-end device, you may want to turn on Multithreaded Rendering – a video setting that can improve CPU performance and graphics quality on high spec devices (you can get more specifics in these patch notes).

What is multithreading How does it improves the performance of Java?

Multithreading saves time as you can perform multiple operations together. The threads are independent, so it does not block the user to perform multiple operations at the same time and also, if an exception occurs in a single thread, it does not affect other threads.

How multithreading improves performance over a single threaded solution?

In a multiprocessor architecture, each thread can run on a different processor in parallel using multithreading. This increases concurrency of the system. This is in direct contrast to a single processor system, where only one process or thread can run on a processor at a time.


1 Answers

For a simple task of iterating 100 elements multi-threading the task will not provide a performance benefit.

Iterating over 100 billion elements and do processing on each element, then the use of additional CPU's may well help reduce processing time. And more complicated tasks will likely incur interrupts due to I/O for example. When one thread is sleeping waiting for a peripheral to complete I/O (e.g. a disk write, or a key press from the keyboard), other threads can continue their work.

like image 154
suspectus Avatar answered Sep 20 '22 18:09

suspectus