swarup wrote:
is, executing 100 threads is better or executing 1 thread is better.
That depends on what each thread is doing.
swarup wrote:
1 thread called 100 times to do the same work (same work each time) OR 10 threas called 10 times to do the same work (same work each time), which method is faster, which method will complete faster
Neither will be faster than the other. On a single processor system, executing the same code 100 times, no matter how many threads you use to run the code will not execute any faster. If the code is 1,000 instructions, start-to-finish, the processor has to execute 1,000,000 instructions to get the job done. Since a single proc can only execute one instruction at a time, it doesn't matter how many threads you use, it's still 1,000,000 instructions to execute, one at a time. Now, if you have multiple processors, the CPU can start executing more than one instruction at the same time. The process CAN run faster, but in no way is this guaranteed. It depends on what this code, that your executing 100 times, is doing and how it affects the CPU, memory controller, caching, I/O, ..., ...
swarup wrote:
thread t{ print 1;} /1st time .. thread t{ print 1;}/100th time OR thread {t0,t1,t2,t3,t4,t5,t6,t7,t8,t9}{print 1;}/1st 10 run .. thread {t0,t1,t2,t3,t4,t5,t6,t7,t8,t9}{print 1;}/last 10run=100 which will complete faster
On a single core CPU, neither. You seem to have the misconception in your head that more threads = faster performance. Nothing could be further from the truth. Threading is a logical division of work, not a replacement for faster processing.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007