简体   繁体   English

用Java编译代码的时间和运行时处理

[英]Compile time and runtime processing of a code in java

I have a piece of Java code and I compiled and ran it. 我有一段Java代码,然后编译并运行了它。 I got an output and I made some changes to it, before compiling and running again. 在编译并再次运行之前,我得到了输出并对它进行了一些更改。

Is there any difference between the time it takes during the first compilation compared to the second compilation. 与第二次编译相比,第一次编译所花费的时间是否有任何区别。 Similarly are there changes between the first runtime to second runtime? 同样,在第一运行时到第二运行时之间是否有变化? Is there any way to find that difference in processing time? 有什么方法可以找到处理时间上的差异吗?

There can be certain difference according to the changes you have made. 根据您所做的更改,可能会有某些差异。 It depends on what your program did and what it does now, i think you can understand that. 这取决于您的程序做了什么以及现在做什么了,我想您可以理解。

To check the time, you can do this by creating a thread that can act like a timer just after the program execution, and stop that thread after all your processes have been done and simply display to see the time. 要检查时间,您可以通过创建一个在程序执行后就可以充当计时器的线程来执行此操作,并在所有进程完成后停止该线程并仅显示以查看时间。

Firstly, I'm unsure why this is important to you. 首先,我不确定为什么这对您很重要。 Perhaps by providing some more context you will get a more detailed answer. 也许通过提供更多背景信息,您将获得更详细的答案。

Comparing compilation time can be achieved using Operating System tools. 使用操作系统工具可以比较编译时间。 For example, on Linux try using time . 例如,在Linux上,尝试使用time

Complete execution time of your two Java programs can be achieved in the same fashion. 您的两个Java程序的完整执行时间可以以相同的方式实现。 However, if you are looking more closely at whether your code changes have improved your execution performance, I would suggest you Google "benchmarking in Java" to find a wealth of information on the correct methods to benchmark code. 但是,如果您正在仔细研究代码更改是否提高了执行性能,我建议您使用Google“使用Java进行基准测试” ,以获取大量有关正确的基准代码测试方法的信息。

If you use Eclipse you can configure Project -> Build Automatically to rebuild the project after every change. 如果您使用Eclipse,则可以配置Project-> Build自动在每次更改后重新构建项目。 So once you want to run it would take minimal time. 因此,一旦您要运行,它将花费最少的时间。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM