Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
3  
Shouldn't Eclipse be slower? –  Dynamic Mar 8 '12 at 23:17
1  
can you show us how you launch the program outside of eclipse? –  Winston Ewert Mar 8 '12 at 23:21
1  
I simply launch it with a .bat file @echo off java permutations –  Lambert Mar 8 '12 at 23:29
2  
Make 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 Mar 8 '12 at 23:32
5  
Related to stackoverflow.com/questions/7206123/… ? –  Patrick Hughes Mar 9 '12 at 1:45

2 Answers 2

up vote 9 down vote accepted

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.

share|improve this answer
    
I ran jvisualvm which showed that the program doesn't use more than 20mb of the heapsize in either shell or eclipse. –  Lambert Mar 9 '12 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_O –  Lambert Mar 9 '12 at 15:30
    
Turns out it was because I was printing each permutation to the console.. issue resolved. Thanks for your answer –  Lambert Mar 9 '12 at 16:21
    
So the problem was the slowness of your console. Always disregard console output when timing. –  user1249 Mar 9 '12 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

share|improve this answer
    
Thanks for the reply, however, I've tried launching my program with the same arguments given for eclipse. Still same result :/ –  Lambert Mar 9 '12 at 15:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.