I've written a java program that generates all repetitive permutations based on the characters and the length given.
When I execute my code in Eclipse, it generates a file with 1,000,000 permutations in only 15 seconds. Yet if I run the program on the same machine in the command prompt using "java permutation" It takes 1 minute 35 seconds to generate the same 1M permutations..
Why is this? And is there anyway I can get this type of performance without using eclipse?
Edit: Added Java VisualVM results
www.craftboom.co.uk/jvm.png - The CPU usage is higher when running in eclipse. Both CPU and memory usage seem to drop to 0 ocassionally in the shell o_O
EDIT2: Turns out it is a problem printing to the screen. Didn't mention it in my original post, but the program prints each permutation to the console.. Commented that out and saved to a file instead.. now running equally fast in both shell and eclipse. :-)
Thanks to all for replies.
-
3Shouldn't Eclipse be slower?Dynamic– Dynamic03/08/2012 23:17:59Commented Mar 8, 2012 at 23:17
-
1can you show us how you launch the program outside of eclipse?Winston Ewert– Winston Ewert03/08/2012 23:21:12Commented Mar 8, 2012 at 23:21
-
1I simply launch it with a .bat file @echo off java permutationsLambert– Lambert03/08/2012 23:29:03Commented Mar 8, 2012 at 23:29
-
2Make sure both launches use the same runtime environment. Find out the one Eclipse uses and give it as a -vm parameter at the command line launch. The runtime environment Eclipse uses when launching is configured in 'Run->Run configurations...', select the one you use (probably under 'Java applications' and look in the JRE tab.Ozan– Ozan03/08/2012 23:32:04Commented Mar 8, 2012 at 23:32
-
5Related to stackoverflow.com/questions/7206123/… ?Patrick Hughes– Patrick Hughes03/09/2012 01:45:37Commented Mar 9, 2012 at 1:45
2 Answers 2
Longer running times indicate a memory issue. Either you swap to disk or you have many more garbage collections than inside Eclipse (because you have a smaller heap).
Run using a profiler, and see where the time is spent. For Java start with jvisualvm in the JDK.
-
I ran jvisualvm which showed that the program doesn't use more than 20mb of the heapsize in either shell or eclipse.Lambert– Lambert03/09/2012 15:16:08Commented Mar 9, 2012 at 15:16
-
Added my results here: craftboom.co.uk/jvm.png It appears that the CPU usage is higher when running in eclipse. Both CPU and memory usage seem to drop to 0 ocassionally in the shell o_OLambert– Lambert03/09/2012 15:30:58Commented Mar 9, 2012 at 15:30
-
Turns out it was because I was printing each permutation to the console.. issue resolved. Thanks for your answerLambert– Lambert03/09/2012 16:21:23Commented Mar 9, 2012 at 16:21
-
So the problem was the slowness of your console. Always disregard console output when timing.user1249– user124903/09/2012 17:40:22Commented Mar 9, 2012 at 17:40
Check the settings in eclipse.ini in your installation (it will contain JVM settings). It's possible that they are configuring the JVM to make more efficient use of it than you are when you run the program.
http://wiki.eclipse.org/Eclipse.ini
http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html
-
Thanks for the reply, however, I've tried launching my program with the same arguments given for eclipse. Still same result :/Lambert– Lambert03/09/2012 15:56:47Commented Mar 9, 2012 at 15:56