I have written a program which has two functions with one thread, and my friend has written same program with two functions with two java threads. Then whose program will run faster?
Obviously your friends' program will run faster as he is using multi threaded programming.
Answer depends on , on what system both of you are running your programs. If you are running in a multi core system, then there is a chance that your friends program may run faster. If you are using single core single threaded system, then both programs will take same time. (Note: In fact your program may run faster than your friends as creating and switching between threads takes some considerable amount of CPU time, though negligible)
Your program with single thread will run faster than your friends program which has two threads.
option 1 and 3 are correct.
Back To Top