Hi All, I've a doubt regarding performance improvement in multithreading. Lets assume I have to execute 100 tasks(Each one will take equal time to execute) and there is no database dependence or there is no need to wait for anything, for each of these tasks.
In this case,lets assume I've 10 threads which are executing these 100 tasks.what performance improvement can I get by using multithreading, instead of using single threading and executing my tasks one by one.
Because as far as I know, even in case of multithreading only one thread can execute at a time (My machine has a single processor). so even in multithreading, all threads will follow some kind of time slicing mechanisms. So I feel that the total time to execuete all the 100 tasks by using Single threading or multithreading is the same. Am I correct (or) I didn't understand something about multithreading regarding performance improvement? Please reply.
Thanks in Advance, VarunJ
SCJP - 98%<br />SCWCD - 89%
Joined: Mar 22, 2005
It sounds like there would be no speedup by using multiple threads, and possible a slowdown due to the overhead of context switching. If all the work to be done is just computation (no disk or network I/O), then you're right that there isn't any scope for parallelism.
The work done is the same, single threaded or multi-threaded. Except that multithreaded has some overhead, so it uses a bit more.
If you are CPU bound and on a single CPU, multi-threading will be slower by the overhead.
If you are IO bound in any way, it may be faster to multi-thread. IO can mean anything here, from waiting for a user to click on a form, to reading a disk or talking to a Sql database on another computer.
Today, quad processor chips are common. Multi-threading can give you nearly a 4 to one improvement in execution time (altho 3 to one is more likely)
Soon, Intel will have 8, 16, and 32 processor chips.