Long start = System.currentTimeMillis();
String s = "1";
for (int i=1;i<1000000000;i++) {
if (s.equals("1"))
s = "2"; //11710,11672,11678
s = (s.equals("1"))? "2":s; //11147,11137,11269
s = (s.equals("1"))? "2":"1";//9539,9528,9647
}
Long end = System.currentTimeMillis();
System.out.println(end - start);
注释是三次测试所花时间,由此得到:
- 赋值常量比赋值变量要快;
- if所花的时间比赋值所花的时间要多;
没有评论:
发表评论