4

I have created a Java program which reads encrypted files from local system and does some processing. Actually I have 20 files to read so I have used threading mechanism to speed up the program execution.

When I run the program in Eclipse it takes more than 30 minutes to complete the execution, whereas if I make a runnable jar and execute the program using command prompt, it takes less than a minute.

Why does running programs in Eclipse take more time than running them in command prompt?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Prathap
  • 1,023
  • 7
  • 19
  • 33
  • 3
    Do you by any chance print a lot to the `System.out`? Because that would immediately explain your observation. – Marko Topolnik Oct 09 '12 at 14:32
  • 1
    @MarkoTopolnik: Yes I used the System.out I print say 5-10k times depending on the program logic.Is that a problem? – Prathap Oct 09 '12 at 14:35
  • 3
    Yes, it is. Remove the printout and you'll see an immediate speedup. Eclipse's Console view is dramatically slower than `stdout` at the command line. – Marko Topolnik Oct 09 '12 at 14:39
  • Not an answer to your question, but just FYI if you want to run an eclipse program from command line you can cd to the `bin/` directory of your eclipse project and run `java package.path.Classname` at any time. Building an executable jar isn't necessary. – dimo414 Oct 09 '12 at 15:03
  • @dimo414 And what about the classpath? – Marko Topolnik Oct 09 '12 at 18:07
  • If everything's in the project, it should work just fine. If you've got a complex build setup, it may not work. Was just a suggestion, since that's what I do from time to time. – dimo414 Oct 09 '12 at 21:36
  • linking possibly related question: https://stackoverflow.com/questions/4591187/running-a-program-in-debug-mode-is-incredible-slow – dasWesen Apr 06 '20 at 12:03

5 Answers5

9

Eclipse's Console view that captures System.out is notoriously slow compared to the regular stdout of the command line. Whenever there is a lot of printing happening in the program, it is to be expected that the program will run significantly slower from Eclipse.

But anyway, unless you are writing a program designed to integrate with other programs via Unix pipes, you should minimize the printing as it will kill performance even at the command line.

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
1

There are some typical mistakes:

  • Maybe you are executing your program in Debug mode.

    Try to use Run (play symbol inside a green circle) instead of Debug (a green bug)

  • Maybe you are executing your program with a different JVM

    Take a look in Project Properties->Java compiler, Window->Preferences->Java->Compiler and Window->Preferences->Java->Installed JREs

  • The output and input interactions with Java Console of Eclipse JDT differ on performance than standard console.

logoff
  • 3,347
  • 5
  • 41
  • 58
0

Ensure that you use the Run action in Eclipse, and not Debug, as the latter really has measurable difference, especially if you use conditional breakpoints.

However, I remember having less significant differences arising from the use of the Debug.

ppeterka
  • 20,583
  • 6
  • 63
  • 78
  • 1
    I am using the Run action only and not using debug mechanism. Still i see huge delay to process compared to command prompt. – Prathap Oct 09 '12 at 14:37
0

I have just did an experiment for you and did not saw so significant difference. I created class that calculates sin() 100000000 times. This program ran ~15 seconds under eclipse and ~14 seconds via command prompt.

So, here are the reasons for slowness in your system I can see at the top of my head:

  1. Be sure that you are not running under debug. Use Run option, not Debug.
  2. Be sure that you do not have some coverage/monitoring developers tools on under eclipse. For example YourKit, Emma etc.
  3. Be sure that your program does not produce significant prints to the console.
  4. Check that you have enough heap memory when running under eclipse
AlexR
  • 114,158
  • 16
  • 130
  • 208
0

Changing jdk 6 to jdk 7 worked perfectly for me. Window->Preferences->Java->Installed JREs