Finding the difference between speed of c++ and java program?

Execution of time of c++ came out to be 0.01 sec
and that of java came out to be 0.43 sec…

Even with such difference in execution time how coders are successfully able to compete in programming contests with java…
is there some method by which I can reach same execution time with java?

I am not talking about only codechef but also about other competitions like codejam.

@v4_adi:

here at codechef java is alloted twice the timelimit as c,c++. :slight_smile:

check this link : http://blog.codechef.com/2009/04/01/announcing-time-limits-based-on-programming-language/

i think all choose timelimit accordingly.

1 Like

So you did one test and found that Java is 43 times slower than C++? Come on!

Java is slower, that is a fact, but the reasons are mainly in I/O and Java, as it is interpreted, needs JVM to start first. In Google Code Jam for example there is 4/8 minutes for small/large input to solve, so as you can see, time limits are no so tight. For TopCoder the strategy is different, JVM is started and input is passed as method argument, so time limit multiplicity is not needed there also.

1 Like

is buffer reader is fastest way to take input in java?

http://blog.codechef.com/2009/04/01/announcing-time-limits-based-on-programming-language/

@v4_adi :
Your findings don’t imply that Java is 43 times slower .

Java takes some time intially for JVM load which is significant , and it will screw up your findings if the time sampling is small .

In case you increase the time taken by C++ program to 1 second by adding some loop and doing something and do the same in Java then Java program should not take more than 2 second , because JVM load is one time cost .

See the below link for more discussion .

http://discuss.codechef.com/questions/13731/c-vs-java-the-unending-time-limit-war?page=1#13775

thnx for the reply guys…now I understand the main reason for longer execution time.