Is running multiple threads faster then a single thread on a single core cpu?
Hi all,
Say I have a code with 3 methods that do some pretty intensive work. Would executing these methods on 3 seperate threads be faster then executing them one after the other on a single core cpu? And what if it's a dual core or HT?
Thnx in advance for your replies.
Re: Is running multiple threads faster then a single thread on a single core cpu?
On a single core I'm pretty sure it would take at least the same time, if not longer. All that's happening is that the CPU is switching between the three threads every x milliseconds. A single core CPU cannot run three threads simultaneously. It could even take longer because the switch between threads takes a little time too.
At least, this is my understanding of the lowest level of multithreading. Perhaps VB.NET handles it differently, but I would be quite surprised if it was faster to use threads.
On a multi-core CPU however, each core should, in theory, be able to run it's own set of threads, so you could run two threads on one core and the third on the other core, then it should be faster. I'm not sure how you can choose which core to run a thread on though, and I'm pretty sure the OS decides that, so I dunno if that works in practice.
Re: Is running multiple threads faster then a single thread on a single core cpu?
Thanks for your reply. That's exactly what I was thinking.
I think you can create multicore apps in .Net 4.0 but not in 3.5 :(.
[EDIT]
I think you are right in saying the OS decides on which core it runs a thread. So you probaly need a very very intensive operation before it will use the 2nd core. As far as I know, most dual core cpu's these days turn the 2nd core off most of the time to make it more energy efficient.
Re: Is running multiple threads faster then a single thread on a single core cpu?
You can create multicore apps in .Net 1.0 (VS 2002)
In .Net 2.0+ I use the BackgroundWorker as it provides events for everything I need to do so I haven't manually done threading like I used to in VS 2003 in quite a while now.
Re: Is running multiple threads faster then a single thread on a single core cpu?
.NET 4.0 adds parallel extensions that make it easier to perform certain tasks in parallel rather than serially. Most specifically, you can perform multiple iterations of a For or For Each loop simultaneously with essentially no extra code. That doesn't make it more multi-threaded than previous versions though, where you could do the same but it would require extra code.
Whether or not multiple threads would run faster on a single core would depend on exactly what work is being done. Remember that your app is sharing time with other processes anyway.
Re: Is running multiple threads faster then a single thread on a single core cpu?
Quote:
As far as I know, most dual core cpu's these days turn the 2nd core off most of the time to make it more energy efficient.
I've never heard of that and when I look at task manager on my quad core PC it shows all 4 cores as being quite active. I'm pretty sure that all of the cores get used pretty much all of the time.
Re: Is running multiple threads faster then a single thread on a single core cpu?
Quote:
Originally Posted by
gonzalioz
As far as I know, most dual core cpu's these days turn the 2nd core off most of the time to make it more energy efficient.
Most of the time? Maybe laptops would shut down a core to save power but certainly not most of the time and desktop systems probably not much at all.
Re: Is running multiple threads faster then a single thread on a single core cpu?
Quote:
Originally Posted by
jmcilhinney
.NET 4.0 adds parallel extensions that make it easier to perform certain tasks in parallel rather than serially. Most specifically, you can perform multiple iterations of a For or For Each loop simultaneously with essentially no extra code. That doesn't make it more multi-threaded than previous versions though, where you could do the same but it would require extra code.
Whether or not multiple threads would run faster on a single core would depend on exactly what work is being done. Remember that your app is sharing time with other processes anyway.
I thought that parallel extensions were available since 3.5. At least that's what I got from this article.
Re: Is running multiple threads faster then a single thread on a single core cpu?
Quote:
Originally Posted by
weirddemon
I thought that parallel extensions were available since 3.5. At least that's what I got from
this article.
The parallel extensions are not a standard part of .NET 3.5 SP1. There is a separate download that will work with .NET 3.5 SP1, although it's unsupported by Microsoft. The parallel extensions will be a standard part of .NET 4.0 when it's released.