English 中文(简体)
Java 执行速度
原标题:Java execution speed

I m new to Java programming.
I am curious about speed of execution 以及 also speed of creation 以及 distruction of objects.
I ve got several methods like the following:

private static void getAbsoluteThrottleB() {
    int A = Integer.parseInt(Status.LineToken.nextToken());
    Status.AbsoluteThrottleB=A*100/255;
    Log.level1("Absolute Throttle Position B: " + Status.AbsoluteThrottleB);
}

以及

   private static void getWBO2S8Volts() {
        int A = Integer.parseInt(Status.LineToken.nextToken());
        int B = Integer.parseInt(Status.LineToken.nextToken());
        int C = Integer.parseInt(Status.LineToken.nextToken());
        int D = Integer.parseInt(Status.LineToken.nextToken());
        Status.WBO2S8Volts=((A*256)+B)/32768;
        Status.WBO2S8VoltsEquivalenceRatio=((C*256)+D)/256 - 128;

        Log.level1("WideB以及 Sensor 8 Voltage: " + Double.toString(Status.WBO2S8Volts));
        Log.level1("WideB以及 Sensor 8 Volt EQR:" + Double.toString(Status.WBO2S8VoltsEquivalenceRatio));

Would it be wise to create a separate method to process the data since it is repetative? Or would it just be faster to execute it as a single method? I have several of these which would need to be rewritten 以及 I am wondering if it would actually improve speed of execution or if it is just as good, or if there is a number of instructions where it becomes a good idea to create a new method.

基本上,使用单一方法处理物体与使用另一种方法处理类似物体时,越快或越快?

It seems like at runtime, pulling a new variable, then performing a math operation on it is quicker then creating a new method 以及 then pulling a varible then performing a math operation on it. My question is really where the speed is at..

These methods are all called only to read data 以及 set a Status.Variable. There are nearly 200 methods in my class which generate data.

最佳回答

无论在方法上还是在方法外,援引一部法典的速度差异微乎其微。 与任务使用正确算法进行特别比较。

我建议你使用这种方法,而不是用于业绩,而是用于维持。 如果你需要修改一条准则,从而引入一种ug或某种东西,而且你在50个不同地方复制/印制了这部法律部分,那么,改变(和插头)要比把它放在一个地方更困难。

因此,不担心采用方法实行的业绩惩罚,因为实际上没有什么东西(甚至更好的是,考试和测验局可能把一些电话连接起来)

问题回答

我认为,S. Lott就你的问题发表评论,也许会完全击中头部——在你确定有关守则实际需要之前,没有达到最佳标准。 否则,你很可能将花费大量时间和精力,以防出现任何收益。

我也作第二次支持性回答,因为采用单独方法与援引准则之间的执行时间差别微不足道(实际上这是我想要做的,但他对我说的话)。 即便是零,如果一个优化的编纂者或联合投资公司决定对这种方法进行跟踪(但不清楚是否在 Java有这种汇编者/联合投资公司)。

然而,单独的方法有一个优势——如果你把你的数据处理代码单独区分为一种方法,你在理论上可以提高业绩,把这一方法从单独的校对上调,从而将你(可能耗费时间)的处理法与你的其他法典脱钩。

我对处决速度以及制造和销毁物体的速度感到奇怪。

在 Java制造物体的速度非常快,除非在极端和异常的情况下,否则你就不必对此表示担忧。

销毁现代 Java中物体的费用为零......除非您使用定本。 即便是think,也很少有人使用定稿。

基本上,使用单一方法处理物体与使用另一种方法处理类似物体时,越快或越快?

相对于正在经历的其他一切而言,差异微不足道。


@S.Lott说:“请不鼓励微粒”。 侧重于采用最适当的算法的简单、明确、准确和正确的书面代码。 只有“micro”才能优化,因为你有明确证据表明存在严重的瓶颈。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签