Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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


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.