When I execute the simple code sample below via Eclipse (version 3.5.2, on Ubuntu 10.04, java version “1.6.0_20”
OpenJDK Runtime Environment (IcedTea6 1.9.9) (6b20-1.9.9-0ubuntu1~10.04.2)
OpenJDK Server VM (build 19.0-b09, mixed mode)), it takes about 10 seconds. When I execute it from my shell (using the same priority and java version), it takes about 40 seconds.
for (int i = 0; i<1000*1000; i++) {
System.out.println(Math.cos(i));
}
I also tried other programs, varying in runtime and amount of output: Each one was much slower in the shell. This was independent of the order of execution. The minimum percentage difference was 85 seconds in Eclipse vs. 145 seconds in shell for a program with very little output.
What’s the reason?
It’s because you’re timing your terminal. Some terminals are just bog-slow when displaying/scrolling text. And your terminal is line buffered, vs the eclipse console likely have more buffering – leading to your program having to wait for your terminal after every line it prints.
Try redirecting the output of your program to a file or /dev/null, and time it.
On my system this makes a bit difference with your little loop: