+ 6
1.5 billion iterations in 10 seconds!
Around 12 hours ago, Agus Mei posted a puzzle (https://www.sololearn.com/discuss/299146/?ref=app). To solve it, I wrote a C++ code. It took around 100 seconds to complete the work. Then, I converted it into a Java program (https://code.sololearn.com/c10BAhXfFGbP/?ref=app) and executed it, and am surprised to see that the execution completed in less than 10 seconds! There are around 1.5 billion iterations in it! I don't know much about C++ but is it really that slow? Or, is there any other reason for this?
6 ответов
+ 9
Sir, I can bet that It wouldn't take more than 6 s on a Win 7 PC with Code::Blocks ...
Perhaps the C++ compilation server is overloaded...
Please try it on an offline compiler!
+ 7
if on the Code Playground depends on how "busy" is the server.
+ 4
would you guys say c++ or java is faster? i always heard it was c++
+ 4
Just executed the C++ version in Turbo C++ compiler. It took around 350 seconds!!!
+ 3
@edward c++ is at least as fast as java. nowadays it's all about optimisation. but not your optimisation but of the compiler. so the real question is which compiler produces faster executable code? the answer: both do well. you will not see any difference by a magnitude anymore. there are edge cases where c++ outperforms java though.
+ 3
@seamiki : Only 1 result will be printed in the code playground before "Time limit exceeded". I executed C++ version offline and Java version in tutorials point online compiler.