if(a) 与 if(a==true) 比较
来源:互联网 发布:mac迅雷开机自动启动 编辑:程序博客网 时间:2024/04/28 05:31
以下测试:
多次测试结果为 if(a)在多次循环的结果下比if (a==true) 要好。
import java.net.UnknownHostException;/** * @author wuyigong * @version createTime:2011-7-2 下午06:16:07 */public class Test {public boolean testT(boolean flag) {boolean a = flag;int m = 0;int n = 0;long st = System.currentTimeMillis();System.out.println("'a == true' start time:" + st);for (long i = 0; i < 1000000000L; i++) {if (a == true) {m++;}}long et = System.currentTimeMillis();System.out.println("'a == true' end time:" + et);long tt = et - st;System.out.println("循环次数:" + m);System.out.println("'a == true' total time:" + tt);System.out.println("---------我是可爱的分割线--------");long st2 = System.currentTimeMillis();System.out.println("'a' start time:" + st2);for (long i = 0; i < 1000000000L; i++) {if (a) {n++;}}long et2 = System.currentTimeMillis();System.out.println("'a' end time:" + et2);long tt2 = et2 - st2;System.out.println("循环次数:" + n);System.out.println("'a' total time:" + tt2);System.out.println("---------我是无敌分割线--------");if (tt > tt2) {return true;} else {return false;}}public static void main(String[] args) throws UnknownHostException {Test test = new Test();boolean bl = test.testT(true);// 经过多次测试'a ==true '的执行效率低于'a'if (bl) {System.out.println("' a==true '所花时间较长,执行效率低。");} else {System.out.println("' a '所花时间较长,执行效率低。");}}}
- if(a) 与 if(a==true) 比较
- if(true==a) 和 if(a==true) 的区别
- Java中对应 if(true==a) 和 if(a==true) 区别的代表性回复
- Java中对应 if(true==a) 和 if(a==true) 区别的代表性回复 【转】
- Java中对应 if(true==a) 和 if(a==true) 区别的代表性回复
- if(a==true)和(true == a)的区别
- if(a);if(!a);if(a!=0);if(a==0)有什么区别?
- if(3 == true)
- angular2中standalone=“true”和Name attribute must be set if ngModel is used within a form的问题
- javascript中if(变量)与if(变量==true)的区别
- String b = a.intern(); if (b == a)
- if和if else的区别if(a>=b&&b>=c) printf("&d\n",a);
- 为什么使用if(0 == a)而不是if(a == 0)
- If given a choice
- if(!a)
- 关于if(a)
- if(a)语句
- If($i==true)和If(true==$i)区别
- android开发时,finish()跟System.exit(0)的区别(转)
- 12、Linux源码下Makefile详解(参照Documentation\kbuild\makefiles.txt和资料)(
- read什么时候阻塞?阻塞有什么表现?
- 输入一个文件名,判断文件类型和拥有的权限
- JMS 中消息的 同步消费 和 异步消费(listener的方式)
- if(a) 与 if(a==true) 比较
- Android 3G连接状态判断
- WindowXP使用"包含文字"搜索,找不到文件之解决办法
- 13、内核Kconfig详解
- [iOS开发高效第三方库之]sqlite3封装库---FMDB
- PHP小技巧 防XSS
- 怎样编写Apple Push Notification服务器
- Makefile教程
- Python通过HTTP协议定期抓取网页