简体   繁体   English

从Eclipse构建时,为什么Java程序比从命令行构建时慢?

[英]When built from eclipse, why is a java program slower than when built from command line?

I did some simple function call and string operation in a loop, the java program runs much faster under command line than launching ( Run as... ) from eclipse... 我在一个循环中做了一些简单的函数调用和字符串操作,与从eclipse启动(Run as ...)相比,java程序在命令行下的运行速度要快得多。

6 lines of output were printed, each line is around 120 characters. 打印了6行输出,每行大约120个字符。 each line is a perf result ranges from 50ms to 300ms. 每行是一个性能结果,范围从50ms到300ms。

The total time is a little more than 2 seconds. 总时间超过2秒。

"much slower" here means, for certain operations ( function call ), I see 20ms vs 300 ms. 这里的“慢得多”意味着,对于某些操作(函数调用),我看到的是20ms与300ms。

After running on console once, the speed on eclipse catches up! 在控制台上运行一次后,Eclipse的速度赶上了!

After I change and build the code in eclipse, the speed on CL will drop if I don't rebuild it with command line. 更改并在eclipse中构建代码后,如果不使用命令行重新构建,则CL的速度将下降。

Looks like some hotspot information is only generated with CL... 似乎某些热点信息仅由CL生成...

Maybe it is just the eclipse console that is slower than your operating systems console? 也许仅仅是Eclipse控制台比您的操作系统控制台要慢? Plus, at a total runtime of ~2 seconds, your benchmark probably is just super inaccurate. 另外,在大约2秒的总运行时间中,您的基准测试可能非常不准确。

Most likely the culprit is memory usage as a result of Eclipse loading, with the possibility that Eclipse is also doing something additional to the executable like swapping class loaders, or starting the java debugger. 造成这种情况的最可能原因是Eclipse加载导致的内存使用情况,并且Eclipse还可能对可执行文件进行其他操作,例如交换类加载器或启动Java调试器。

I would say the most likely answer however is simply: Eclipse uses a lot of resources, especially memory, and is starving the system a bit, leading to swapping, and decreased performance. 我想说的是,最可能的答案很简单:Eclipse使用了大量资源,尤其是内存,并且使系统有点饿,从而导致交换和性能下降。 YMMV, and there's no guarantee I'm right without seeing your system, it's just my best guess. YMMV,并且不能保证我不看您的系统就对,这只是我的最佳猜测。

I do agree with other comments that Eclipse is doing something when running the application and printing the console. 我确实同意其他评论,即Eclipse在运行应用程序并打印控制台时正在执行某些操作。

Eclipse has its own compiler (usually referred as Eclipse JDT) which supports incremental compilation. Eclipse具有自己的编译器(通常称为Eclipse JDT),该编译器支持增量编译。 There is a possibility that the binary compiled by Eclipse is not optimized as it is compiled by javac. 由于Eclipse编译的二进制文件是由javac编译的,因此未对它进行优化。

These two compiler serves different purpose, JDT mainly enable Eclipse to provide state-of-art refactoring and auto-completion, and javac spends a lot of effort doing optimization. 这两个编译器具有不同的用途,JDT主要使Eclipse提供最先进的重构和自动完成功能,而javac则花费大量精力进行优化。

I would say it's understandable that the application would run slower with all the Eclipse baggage underneath. 我想说应用程序在所有Eclipse行李的下面运行会更慢,这是可以理解的。 Eclipse spawns the JVM process as a child and I am sure still does its own 'magic'. Eclipse将JVM进程作为一个子进程产生,我敢肯定,它仍然具有自己的“魔力”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在Eclipse中和从命令行运行Java程序时,ThreadPoolExecutor的行为会有所不同? - Why ThreadPoolExecutor behaves differently when running Java program in Eclipse and from command line? 与从Netbeans运行时相比,Java程序作为dist生成要慢 - Java program is slower as a dist build than when ran from Netbeans 在Eclipse中运行Java程序,就像从命令行运行一样 - Running a Java program in Eclipse as if from command line Java程序在Netbeans中可以正常运行,但是从内置的JAR运行时,它不起作用 - Java program runs fine within Netbeans, but when running from a built JAR it does not work 调用bazel构建的Java程序的原始命令行是什么? - What is the raw command-line to call a bazel built java program? 为什么我的 Java 代码更改在从命令行运行但在 Eclipse 中运行时没有反映出来? - Why are my Java code changes not being reflected when ran from command line but working in Eclipse? 为什么从命令行运行可执行jar比使用Eclipse运行的同一个项目使用更多的ram? - Why an executable jar when run from a command line uses much more ram, than the same project run from Eclipse? 从命令行执行Java程序时文件未写入 - File not writing when java program is executed from command line 从命令行运行Java程序时无法加载资源 - Failing to load resource when running java program from command line 部署到tomcat时,长时间运行的多线程应用程序运行速度比从命令行运行时慢4倍 - Long running multi threaded application runs 4x slower when deployed to tomcat than when run from command line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM