|
-
Dec 23rd, 2009, 09:34 AM
#1
Thread Starter
Hyperactive Member
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.
-
Dec 23rd, 2009, 09:45 AM
#2
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.
-
Dec 23rd, 2009, 10:16 AM
#3
Thread Starter
Hyperactive Member
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.
Last edited by gonzalioz; Dec 23rd, 2009 at 10:19 AM.
-
Dec 23rd, 2009, 10:44 AM
#4
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.
-
Dec 23rd, 2009, 05:52 PM
#5
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.
-
Dec 23rd, 2009, 06:46 PM
#6
Re: Is running multiple threads faster then a single thread on a single core cpu?
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.
-
Dec 23rd, 2009, 07:21 PM
#7
Re: Is running multiple threads faster then a single thread on a single core cpu?
 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.
-
Dec 23rd, 2009, 07:30 PM
#8
Re: Is running multiple threads faster then a single thread on a single core cpu?
 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.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Dec 23rd, 2009, 08:41 PM
#9
Re: Is running multiple threads faster then a single thread on a single core cpu?
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|