gpt4 book ai didi

java - 哪种编程练习更快?

转载 作者:行者123 更新时间:2023-12-02 11:21:39 25 4
gpt4 key购买 nike

我用Java创建了一个小型应用程序,因为我不是Java专家,所以我的程序效率不高(我所说的效率是指更少的执行时间,即我想要更快的结果)。如果有经验的人能回答我的以下问题,我将不胜感激:

哪一个更快:

问题1

boolean b1;
b1=true;

boolean b1= true;

问题2

boolean b1;
boolean b2;

boolean b1, b2;

问题3

for (int index goes to some iterations)
{
MyCustomClass obj = new MyCustomClass ();
//Some other code goes here
}

MyCustomClass obj = new MyCustomClass ();
for (int index goes to some iterations)
{
obj.Reset();// Assume .Reset() have same codes as zero argument constructor has
//Some other code goes here
}

提前致谢

最佳答案

  1. 都不是。这甚至不是微观优化。
  2. 都不是...
  3. 取决于 Reset() 与创建新对象生成了多少垃圾。

关于java - 哪种编程练习更快?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6863517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com