2005-09-08
J2ME优化——for循环优化
这里我主要和大家一起讨论for循环的优化情况,主要讨论循环的变量条件使用递增和递减的差距,下面让我们来看这段代码。
package Optimize;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class forTest extends MIDlet {
public forTest() {
super();
// TODO Auto-generated constructor stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
long timer = 0L;
timer = System.currentTimeMillis();
for (int k = 1000000; k > 0; k--) {
}
System.out.println(System.currentTimeMillis() - timer);
timer = System.currentTimeMillis();
for (int k = 0; k < 1000000; k++) {
}
System.out.println(System.currentTimeMillis() - timer);
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
}
在各自循环判断一百万次后,控制台输出的值有120毫秒的差值,递减的for循环要快点,建议在循环次数较大时使用递减的方式。
发表评论
- 浏览: 86122 次
- 性别:

- 来自: 重庆

- 详细资料
搜索本博客
最新评论
-
jquery图书列表
那本jQuery Reference Guide就算了……还不如不看呢……
-- by shawphy -
你会用Protocol Buffers吗 ...
为什么只做配置文件用?我想google来使用Protocol Buffers,主 ...
-- by menlong999 -
你会用Protocol Buffers吗 ...
为什么只做配置文件用?我想google来使用Protocol Buffers,主 ...
-- by menlong999 -
你会用Protocol Buffers吗 ...
引用XML是对机器友好的,着你都读得懂,还怕读不懂Protocol Buffer ...
-- by Sam1860 -
你会用Protocol Buffers吗 ...
Protocol Buffers好像是一个二进制协议。自Web Services ...
-- by hax






评论排行榜